使用ExtJS加载商店时出错

时间:2012-05-15 10:59:01

标签: json extjs

Ext.define('Olvldefnition', {
    extend: 'Ext.data.Model',
    fields: [
        {
                        name : 'defKey'
        },
        {
            name : 'defStructKey',
            type : 'int'
        },
        {
            name : 'defLevelNo',
            type : 'int'
        }, {
            name : 'defLevelDiscP',
            type : 'string'
        }, {
            name : 'defLevelDiscS',
            type : 'string'
        }, {
            name : 'defSeqNo',
            type : 'int'
        }
    ]
});


var storeDef = Ext.create('Ext.data.Store', {
    id: 'storeDef',
    model: 'Olvldefnition',
    proxy: {
       type: 'jsonp',
       api : {
    read : 'definition/view.action'
},
        reader: {
            type: 'json',
             root: 'data',
             idProperty: 'defKey',
             successProperty : 'success',
             messageProperty : 'message'
        }
 }
}); 

这是我的代码,它获取如下的JSON数据。

{
"total":3,
"data":[
{"modifiers":{"status":"A","effstartdate":"2012-04-02 00:00:00.0","effenddate":"2012-04-26 00:00:00.0","updateUser":"ARCSADMIN","updateDate":"2012-04-16 16:04:29.162","remarks":null,"entryDate":"2012-04-07 19:34:28.923","entryUser":"ARCSADMIN"},
"defKey":105,
"defSeqNo":2,
"defStructKey":73,
"defLevelNo":1,
"defLevelDiscP":"Branch",
"defLevelDiscS":"Branch",
"olvstructure":{"modifiers":{"status":"A","effstartdate":"2012-04-06 00:00:00.0","effenddate":"2012-04-27 00:00:00.0","updateUser":"ARCSADMIN","updateDate":"2012-04-06 20:03:43.817","remarks":"Remark","entryDate":"2012-04-06 20:03:37.252","entryUser":"ARCSADMIN"},"olsKey":73,"olsSeqNo":1,"olsLevel":3,"olsSeperator":"-"}},{"modifiers":{"status":"A","effstartdate":"2012-04-02 00:00:00.0","effenddate":"2012-05-23 00:00:00.0","updateUser":"ARCSADMIN","updateDate":"2012-04-30 12:22:12.899","remarks":null,"entryDate":"2012-04-07 19:33:58.405","entryUser":"ARCSADMIN"},"defKey":104,"defSeqNo":1,"defStructKey":73,"defLevelNo":2,"defLevelDiscP":"Dept1","defLevelDiscS":"Dept1","olvstructure":{"modifiers":{"status":"A","effstartdate":"2012-04-06 00:00:00.0","effenddate":"2012-04-27 00:00:00.0","updateUser":"ARCSADMIN","updateDate":"2012-04-06 20:03:43.817","remarks":"Remark","entryDate":"2012-04-06 20:03:37.252","entryUser":"ARCSADMIN"},"olsKey":73,"olsSeqNo":1,"olsLevel":3,"olsSeperator":"-"}},{"modifiers":{"status":"I","effstartdate":null,"effenddate":null,"updateUser":null,"updateDate":null,"remarks":null,"entryDate":"2012-04-19 13:52:04.676","entryUser":"ARCSADMIN"},"defKey":118,"defSeqNo":3,"defStructKey":73,"defLevelNo":3,"defLevelDiscP":"sdasda","defLevelDiscS":"dsd","olvstructure":{"modifiers":{"status":"A","effstartdate":"2012-04-06 00:00:00.0","effenddate":"2012-04-27 00:00:00.0","updateUser":"ARCSADMIN","updateDate":"2012-04-06 20:03:43.817","remarks":"Remark","entryDate":"2012-04-06 20:03:37.252","entryUser":"ARCSADMIN"},"olsKey":73,"olsSeqNo":1,"olsLevel":3,"olsSeperator":"-"}}],"message":"view","success":true}

但是它显示了像这样的错误

SCRIPT1004: Expected ';' 
view.action?_dc=1337079455042&page=1&start=0&limit=25&callback=Ext.data.JsonP.callback1, line 1 character 9

2 个答案:

答案 0 :(得分:2)

也许问题是代理type: 'jsonp'

因为在您的示例中,我只看到json而非jsonp且您的api网址位于同一台服务器上,所以为什么不使用json代替jsonp

示例:

var storeDef = Ext.create('Ext.data.Store', {
    id: 'storeDef',
    model: 'Olvldefnition',
    proxy: {
        type: 'ajax',
        api : {
            read : 'definition/view.action'
        },
        reader: {
            type: 'json',
            root: 'data',
            idProperty: 'defKey',
            successProperty : 'success',
            messageProperty : 'message'
        }
    }
});

答案 1 :(得分:0)

我认为你在某处遇到了简单的语法错误。它与解析JSON数据无关。