extjs - 如何在json-store中添加记录

标签 extjs

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/

相关文章:

javascript - Ext JS 中是否有其他方法,例如 jQuery .unwrap 方法?

javascript - Selectfield 卡在 Sencha Touch 中并且事件在选择时未触发

extjs - 通过 id 或 itemId 获取 TabPanel 的 Tab

arrays - 如何使用组合框的第一个存储值作为默认值EXTJS

javascript - 使用 ExtJS 检索 div id 值

javascript - 动态创建Ext.panel

javascript - EXT JS 无法同时加载多个页面

testing - Siesta - 根据特定条件运行子测试(来自另一个测试文件)

javascript - Extjs Restful Store,批量发送请求?

extjs - 在 extjs 的选项卡面板的标题中添加按钮