我正在使用extjs 4.1从数组加载数据。但是数据没有被加载。我的代码正在关注
var ghi=[];
var ghi=[{res :'25' , dir:'25',def: '56',dhr: '35',mon:'Jan'},......];
//alert("In Proces");
Ext.define('MyModelghi', {
extend: 'Ext.data.Model',
fields: [{name: 'res', type: 'float'},{name:'dir',type:'float'}, {name:'def',type:'float'},{name:'dhr',type:'float'},{name:'mon',type:'string'}]
});
storecahr2=Ext.create('Ext.data.Store', {
model: 'MyModelghi',
data: ghi
});
如果我取消对警告的评论,那么数据会在商店中加载,否则如果评论提醒它会在商店中返回空值。任何人都可以告诉我我需要做什么来避免除警报之外的这个空值。
答案 0 :(得分:2)
您可以在此代码中找到答案。
var ghi = [{
'res': '25',
'dir': '25',
'def': '56'
}];
alert('In Process');
var mymodel = Ext.define('MyModelghi', {
extend: 'Ext.data.Model',
fields: [{name: 'res', type: 'float'},{name:'dir',type:'float'}, {name:'def', type: 'float'}]
});
var storecahr2 = Ext.create('Ext.data.Store', {
model: mymodel,
data: ghi
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: storecahr2,
columns: [{
text: 'Res',
dataIndex: 'res'
}, {
text: 'Dir',
dataIndex: 'dir',
flex: 1
}, {
text: 'Def',
dataIndex: 'def'
}],
height: 200,
width: 400,
renderTo: Ext.getBody()
});