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

how to convert Json Data to variable in EXTJS

本文关键字:EXTJS 变量 转换 Json 数据      更新时间:2023-09-26

我有数据json从MYSQL获得。但我想从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]
        ]

我该怎么做呢?

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属性,因为我猜您想使用int/float。