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}]);
    }
}

问题出在什么地方,谁能告诉我?


2个回答

赞成 2 反对 已采纳

你需要定义一个record type:

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

一个比较简单的办法:

listeners: {
    load: function( xstore ,  record , option ) {
        var u = new xstore.recordType({  jfields : 'monthly'  });
        xstore.insert(record.length, u);
    }
}