var store = new Ext.data.JsonStore({
id:'jfields',
totalProperty:'totalcount',
root:'rows',
url: 'data.php',
fields:[{ name:'jfields' },
{ name:'firstyear' , mapping :'firstyear' , type:'float' },
{ name:'secondyear', mapping :'secondyear', type:'float' },
{ name:'thirdyear' , mapping :'thirdyear' , type:'float' },
{ name:'fourthyear', mapping :'fourthyear', type:'float' },
{ name:'fifthyear' , mapping :'fifthyear' , type:'float' } ]
}
});
我想要的是在这家商店的末尾添加数据,但我完全困惑,我所做的是向其中添加以下代码但不起作用。
listeners: {
load : function(){
BG_store.add([{"jfields":"Monthly","firstyear":22.99,"secondyear":21.88,"thirdyear":21.88,"fourthyear":22.99,"fifthyear":21.88}]);
}
}
但我认为我的概念还没有弄清楚,请任何人展示一些如何做到这一点的方法。
最佳答案
您需要定义一个记录类型,创建它并使用它,例如:
TaskLocation = Ext.data.Record.create([
{name: "id", type: "string"},
{name: "type", type: "string"},
{name: "type_data", type: "string"},
{name: "display_value", type: "string"}
]);
然后:
var record = new TaskLocation({
id: Ext.id(),
type: "city",
type_data: "",
display_value: "Brighton"
});
然后:
my_store.add(record);
my_store.commitChanges();
请记住,当数据存储在存储中时,它的格式与您发送的格式不同,而是采用 Record 对象。
关于extjs - 如何在json-store中添加记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3405437/