当前位置: 代码迷 >> JavaScript >> 求教EXTJS读取json的步骤
  详细解决方案

求教EXTJS读取json的步骤

热度:4   发布时间:2013-07-25 16:22:17.0
求教EXTJS读取json的方法
初次接触extjs,写不来,求帮助

简单来说,我要做一个图表,看了点示例,但是现在想要把数据写在json文件里调用,不知道该怎么写


Ext.onReady(function(){
var dataStore = new Ext.data.JsonStore({
fields:['name', 'percentage'],
data: [
{name :'小于30岁', percentage : 2},
{name :'30-40岁', percentage : 4},
{name :'40-50岁', percentage : 3},
{name :'50岁以上', percentage : 3}
]
});
Ext.create('Ext.panel.Panel', {
title : '员工年龄分布图',
width: 400,
height: 400,
renderTo: Ext.getBody(),
layout: 'fit',
items : [{
xtype : 'chart',
store : dataStore,
axes: [{……………………
});
});


这是某个示例,求改
Ext?JS

------解决方案--------------------
参考下把
------解决方案--------------------

var dataStore = new Ext.data.JsonStore({
        fields:['name', 'percentage'],
        url:'xxx.json',
        totalProperty : "total",
root: 'root'
    });

xxx.json文件:

{"total":4,"root":[
            {name :'小于30岁', percentage : 2},
            {name :'30-40岁', percentage : 4},
            {name :'40-50岁', percentage : 3},
            {name :'50岁以上', percentage : 3}
        ]}
  相关解决方案