如何在EXTJS中将Json数据转换为变量

时间:2015-09-03 06:36:43

标签: javascript mysql json extjs

我有来自MYSQL的数据json。但我希望从json转换为数组数据。

Ext.define('DWP3.store.konten.Coba', {
extend: 'Ext.data.Store',
alias: 'store.coba',
 storeId: 'coba',
uses: [
    'Ext.data.Store'
],


        fields: [
           {name: 'periode'},
           {name: 'Teknik Informatika S1'},
        ],
        proxy: {
            type: 'ajax',
            url : 'resources/data/load2.php',
            reader: {
            type: 'json',
            rootProperty: 'view_aktif'
            }
        },
         autoLoad: true,

  });

我希望像这样从json转换数据:

       var data= [
            ['2009', 94.7 ],
            [ '2010', 96.5 ],
            [ '2011', 98.6 ],
            [ '2012',  70.8 ],
            [ '2013', 83.3]
        ]

我该怎么做?

1 个答案:

答案 0 :(得分:0)

ExtJS存储将记录作为对象而不是数组。

幸运的是:JavaScript数组与使用ExtJS存储处理它们的对象相似。数组['2009', 94.7 ]的处理与对象{0:'2009', 1:94.7 }没有任何不同,因此您必须执行以下操作:

fields: [
   {name: 'periode',mapping:0},
   {name: 'Teknik Informatika S1',mapping:1},
],

(注意:我不确定是否允许带空格的名称。我的测试没有使用此名称)

如需进一步阅读,请比较ExtJS mapping属性的文档。

我还建议你看看type属性,因为我猜你想要使用ints / floats。