0

这是我的代码:

function getStore (json) {
    var reader = new Ext.data.JsonReader({
       root : 'data',
       successProperty: 'success',
       totalProperty: "rows",
       fields : [
        {name: 'num', allowBlank:'true'},
        {name: 'date', dateFormat:'d.m.Y H:i:s', type: 'date'},
        {name: 'signerFIO', type: 'string'},
        {name: 'checkSign', type: 'boolean'}
       ]
   });

   var store = new Ext.data.JsonStore ({
     data   : json,
     reader : reader
   });

   return store;
}

来自服务器的数据是:{"data":[{"num":"111","signerFIO":"hello","checkSign":true,"date":"25.05.2012"}],"success":1,"rows":1}

我尝试将“json”函数参数设置为原始 json(到达时)和 Ext.util.JSON.decode(response.responseText)

我已经在 FF 和 FireBug 中尝试过这段代码,但我遇到了奇怪的h is undefined错误。

有人知道出了什么问题吗?

更新

var store = new Ext.data.JsonStore ({
    data     : json,
    fields   : ['data']
});

在没有错误的情况下为我工作,但也没有加载数据。

4

2 回答 2

1

我真的不确定你想用这段代码做什么,但这会让它工作(假设 json 是一个解码的对象而不是一个字符串):

Ext.define("MyItem", {
    extend: "Ext.data.Model",
    fields: [
        {name: 'num', allowBlank:'true'},
            {name: 'date', dateFormat:'d.m.Y H:i:s', type: 'date'},
            {name: 'signerFIO', type: 'string'},
            {name: 'checkSign', type: 'boolean'}
    ]
});
function getStore (json) {

   var store = new Ext.data.JsonStore ({
     data:  json.data,
     model: MyItem
   });

   return store;
}
于 2012-06-25T18:09:55.080 回答
0

问题出在读者身上(其实我也不知道是什么问题)。这:

function getStore (jsonRequestUrl) {
var store = new Ext.data.JsonStore ({
    autoLoad : false,
    proxy    : new Ext.data.HttpProxy({ url: jsonRequestUrl, method: 'POST' }),
    root     : 'data',
    successProperty : 'success',
    totalProperty   : "rows",
    idProperty      : "id",
    fields : [
        {name: 'num', type: 'string', mapping: 'num'},
        {name: 'signerFIO', type: 'string', mapping: 'signerFIO'},
        {name: 'checkSign', type: 'boolean', mapping: 'checkSign'},
        {name: 'date', dateFormat:'d.m.Y', type: 'date', mapping: 'date'}
    ]
});
store.load();

return store;
}

为我工作。

于 2012-06-26T11:14:15.500 回答