Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用JavaScript在EXTJS Simplestore中加载存储数据_Javascript_Extjs - Fatal编程技术网

无法使用JavaScript在EXTJS Simplestore中加载存储数据

无法使用JavaScript在EXTJS Simplestore中加载存储数据,javascript,extjs,Javascript,Extjs,我正在尝试将数据重新加载到存储中,该存储将被GridPanel进一步使用。我的代码如下: Ext.onReady(function(){ myData = [ ['document','listsk','123','','','rat'], ['hiiiii','himself','rest','','','lap'] ]; // create the data store store = new Ext.data.Si

我正在尝试将数据重新加载到存储中,该存储将被GridPanel进一步使用。我的代码如下:

Ext.onReady(function(){

    myData =     [
        ['document','listsk','123','','','rat'],
        ['hiiiii','himself','rest','','','lap']
    ];

    // create the data store
    store = new Ext.data.SimpleStore({
        fields: [
            {name: 'cat'},
            {name: 'desc'},
            {name: 'edcsId'},
            {name: 'transformedEDCSUrl'},
            {name: 'transformedFormatsUrl'},
            {name: 'lineNotes'}
        ]
    });
    store.loadData(myData);

    // create the Grid
    grid = new Ext.grid.GridPanel({
        store: store,
        columns: [
           {header: "<b>Category</b>",  sortable: true, dataIndex: 'cat'},
           {header: "<b>Description or Document Title</b>", sortable: true,  dataIndex: 'desc'},
           {header: "<b>EDCS ID #</b>", sortable: true, renderer: renderEDCSUrl, dataIndex: 'edcsId'}
           {header: "<b>URLs to Formats</b>", renderer: renderFormatsUrl},
           {id: 'lineNotes', header: "<b>Line Notes</b>", sortable: true, dataIndex: 'lineNotes'}
        ],
        viewConfig: { 
            forceFit: true
        },
        autoExpandColumn: 'lineNotes',
        stripeRows: true,
        collapsible: true
    })

    reload = function refreshGrid(data){
        store.loadData(data);
    }
})
javascript函数refreshGrid中的数据变量也是相同的:

[
    ['document','listsk','123','','','rat'],
    ['hiiiii','himself','rest','','','lap']
]
我正在调用函数refreshGrid,如下所示:

function load(response) {  
    reload(response.substring(response.indexOf('myData') + 9, 
           response.indexOf('function renderABC') - 2));
}
对我来说,这看起来像是一个JSON解析问题,因为数据从后端正常传输。这是解析来自后端的JSON字符串的最佳方法。
store.loadData
的javascript invation的行为是,数据变量中的每个字符在网格中被视为单独的行,如下所示:


看起来您向存储提供的是字符串数组,而不是预期的数组数组


因此,store将数组的每个值(实际上是字符串)视为一个数组。一旦字符串支持按索引引用(至少在非IE浏览器中),您就会得到所描述的行为。

对于所有面临此问题的人来说,一个快速的解决方法是使用eval函数,或者使用一些JSON库。

因为您的问题是关于存储和网格的客户端问题,我建议您删除任何服务器端引用(
extuf.append(“…”;
),而不是
rowDataString.toString()
显示结果。为了便于理解和回答您的问题:)您没有向我们展示您的
网格
是如何配置的。您是否定义了与门店
字段
配置匹配的
列模型
?据我所知,网格需要被明确告知如何处理存储中的数据。但是,在javascript字符串变量“data”中,每个字符仍然被视为单独的行。如果我从ColumnModel中删除渲染器,那么上面的代码(修订版4)对我来说效果很好。那么有什么方法可以使用字符串变量来模拟行为:myData=[['document'、'listsk'、'123'、''、''、'rat'],[hiiiii',hivii',rest','lap','lap'];不需要。解决方案是按照ExtJS作者的意图,开始使用数组数组,而不是字符串数组。目前,我通过在Javascript中使用eval函数实现了我想要的。将询问客户是否同意使用javascript库将字符串转换为javascript中的JSON。您已经准备好使用这样的库了。ExtJs有内置的Ext.decode和Ext.encode方法。永远不要使用eval。
function load(response) {  
    reload(response.substring(response.indexOf('myData') + 9, 
           response.indexOf('function renderABC') - 2));
}