method addListener

void addListener(object collectionListener,value context);

Argumente

Zurückgegebener Wert

This method attaches a listener to the liveDictionary object.
function DictionaryOperationCodeToString(opcode)
{
    var res = "unknown";
    switch(opcode)
    {
        case 0:
            res = "Refresh";
            break;
        case 1:
            res = "Set";
            break;
        case 2:
            res = "Remove";
            break;
    }
    return res;
}

function DictionaryListener()
{
	this.onDictionaryModified = onDictionaryModifyFunc;
}

function onDictionaryModifyFunc(dictionary, operation, key, context)
{
    var str = "Callback: operation is " + DictionaryOperationCodeToString(operation);
    if (operation != 0)
    {
        str += ", Dictionary[" + key + "]";
        if (operation != 2)
        {
            str += "=" + dictionary.valueForKey(key);
        }
    }
    alert(str);
}

//main
function main()
{
    var liveDictObj = shell.serviceManager.basics.liveDictionary;
    var dictListenerObj = new DictionaryListener();
    liveDictObj.addListener(dictListenerObj, null);

    liveDictObj.setValueForKey(217, "two");
    liveDictObj.setValueForKey("for removal", "four");
    liveDictObj.removeValueForKey("four");
	
    liveDictObj.removeListener(dictListenerObj);
}