我是Extjs的新手,使用ExtJs 4.1.0,我创建了一个树面板,其中的节点是从JSON存储库生成的。这很好,但用户试图在按钮点击时显式添加/删除新记录(或节点),这从json响应文本显示数据被添加或删除,但它不刷新树面板,请在这里帮助我。我尝试了很多方法,比如tree.getStore.Load()或treepanel.root.reload();没有任何作用,并将错误视为空。
function MakeTreePanel(_store) {
LeftPlanObjectenPanel = Ext.create('Ext.tree.Panel', {
store: _store,
id: 'mytree',
autoShow: true,
//height: 500,
rootVisible: false,
clearOnLoad: true,
border: false,
renderTo: Ext.getBody()
// listeners: {
// itemclick: function (view, record, item, index, e) {
// fnClickLeaf(record.raw.id);
// //alert(record.raw.id);
// }
// }
});
}
我的商店就像:
PlanObjectenStore = Ext.create('Ext.data.TreeStore', {
autoLoad: true,
autoSync: true,
root: {
expanded: true
}
});
Ext.Ajax.request({
url: 'DS_PlanObject.asmx/GetPlanObjectsByMindplanInJSON',
timeout: ExtTimeoutVar,
method: 'POST',
headers: { 'Content-Type': 'application/json;charset=utf-8' },
jsonData: { DecisionType: DecisionType, DecisionNumber: DecisionNumber, DecisionTypeNumber: DecisionTypeNo, MindPlanID: MindPlanID },
success: function (result, request) {
//alert("Response: " + result.responseText);
PlanObjectJsonCollectionData = Ext.decode(result.responseText);
if (LeftPlanObjectenPanel == null) {
PlanObjectenStore = eval('{' + PlanObjectJsonCollectionData.d[0].naam + '}');
//PlanObjectenStore = eval('{Ext.create(\'Ext.data.TreeStore\', { root: { expanded: true, children: [{ text: "ABCD1234", expanded: true, id: "root", children: [{ text: "plangebied", expanded: true, id: "plangebied" }, { text: "ehs", expanded: true, id: "23" }, { text: "ehs text", expanded: true, id: "24" }, { text: "ehs water", expanded: true, id: "25" }, { text: "lkjlkj", expanded: true, id: "17" }, { text: "new praveen", expanded: true, id: "19" }, { text: "nitin kumar soni", expanded: true, id: "22" }, { text: "nitin soni", expanded: true, id: "20" }, { text: "pks", expanded: true, id: "12" }, { text: "test another", expanded: true, id: "18" }, { text: "test praveen", expanded: true, id: "8" }, { text: "Test1", expanded: true, id: "1" }, { text: "Test2", expanded: true, id: "2" }, { text: "Test3", expanded: true, id: "3" }, { text: "Test4", expanded: true, id: "4" }, { text: "Test5", expanded: true, id: "5" }, { text: "Test6", expanded: true, id: "6" }, { text: "testkees", expanded: true, id: "7" }, { text: "vcvc", expanded: true, id: "15" }, { text: "yes sharma ji", expanded: true, id: "11"}]}]} });}');
MakeTreePanel(PlanObjectenStore);
}
},
failure: function (result, request) {
alert('error:LoadTree method' + result.responseText);
var jsonData = Ext.decode(result.responseText);
myMask.hide();
}
});
On Saving record in table: I use to call like this:
LeftPlanObjectenPanel.root.reload();
请告诉我如何重新加载我的树状面板。 谢谢
答案 0 :(得分:0)
通常,我们可以使用:
treeStore.getRootNode().appendChild(...);
示例强>:
var decodedData = Ext.JSON.decode(data);
treeStore.getRootNode().appendChild(decodedData);