在ItemFileWriteStore中添加带_reference的新项

时间:2012-03-23 05:18:06

标签: javascript dojo

现在我可以使用store.newItem()添加项目。添加后,它将它放在旧的JSON数据之后。

但是如何将它放在children中(查看我的代码)?

{
    'id': 'WMD',
    'name': 'Web MD.',
    'type': 'continent',
    'children': [
        {
            '_reference': 'PUTTANONE'
        }
    ]
}

如何将其添加到该位置?

1 个答案:

答案 0 :(得分:0)

现在我已经完成了我的问题。我从this site

得到了这个想法

我仍然使用store.newItem但必须保留返回的值,并使用store.save

newValueTreeAdded = store.newItem({
    id: name + lastName,
    name: name + " " + lastName,
    type: 'fullName'
});

if(store.isDirty()){
    store.save({onComplete: saveStoreDone, onError: saveStoreFailed});
}

完成后,请查看function saveStoreDone

function saveStoreDone(){
    store.fetch({ onComplete: onCompleteFetch });
}

并查看function onCompleteFetch

function onCompleteFetch(items, request){
    var selectDepartment = (radioWMDChoose)? 0 : 1; //select root node to add child
    var tempChild = store.getValues(items[selectDepartment],'children');
    var indexChild = tempChild.length;

    tempChild[indexChild] = newValueTreeAdded; //newValueTreeAdded is come from store.newItem
    store.setValues(items[selectDepartment], "children", tempChild);                            
}

完成!的 :d