现在我可以使用store.newItem()
添加项目。添加后,它将它放在旧的JSON数据之后。
但是如何将它放在children
中(查看我的代码)?
{
'id': 'WMD',
'name': 'Web MD.',
'type': 'continent',
'children': [
{
'_reference': 'PUTTANONE'
}
]
}
如何将其添加到该位置?
答案 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 强>