如何在json-store中添加记录 [英] How to add records in json-store

查看:94
本文介绍了如何在json-store中添加记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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' } ]

    }                                                    
});

我想要的是在这个商店的最后添加数据,但我完全困惑,什么我做的是添加以下代码,但不能正常工作。

What I want is to add data at the end for this store , but I am totally confused , what I did is I add the following code to it but not working.

listeners: {
    load : function(){
        BG_store.add([{"jfields":"Monthly","firstyear":22.99,"secondyear":21.88,"thirdyear":21.88,"fourthyear":22.99,"fifthyear":21.88}]);
    }
}

但我不认为我的概念被清除,请任何机构都会显示出如何做到这一点。

But I do not think my concept are cleared ,Please any body show some way how to do it .

推荐答案

你需要定义一个记录类型,创建它, :

You need to define a record type, create it and at it, e.g:

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();

记住数据在商店的时间,它与您发送的格式不一样但在记录对象中。

Remember by the time the data is in the store it's not in the same format as you sent it down but in Record objects instead.

这篇关于如何在json-store中添加记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆