您的位置:首页 > 移动开发

Extjs store load json data,store fields mapping can't show data

2013-12-03 15:26 423 查看
 Extjs ext4.2.2.1144

 store fields mapping : 'user.lastName' store.loadData()后数据显示不正确,编辑显示也不正确,用store.loadRawData()可以。

loadData through reader use loadRawData

Ext.onReady(function() {
Ext.create('Ext.data.Store', {
storeId : 'emptyStore',
fields : [],
data : []
});

var grid = Ext.create('Ext.grid.Panel', {
title : 'usergrid',
tbar : [{
text : 'test',
handler : function(b, e) {

var store = Ext.create('Ext.data.Store', {
storeId : 'userStore',
fields : [{
name : 'user',
mapping : 'user.lastName'
}, {
name : 'address',
mapping : 'address.country'
}]
});
var columns = [{
text : 'user',
dataIndex : 'user',
flex : 1,
editor : 'textfield'
}, {
text : 'address',
dataIndex : 'address',
editor : 'textfield',
renderer : function(value, metaData,
record, rowIndex, colIndex, store,
view) {
return value;
}
}];

grid.reconfigure(store, columns);
store.loadRawData([{
user : {
firstName : 'wan',
lastName : 'donglei'
},
address : {
country : 'zhongguo',
city : 'nanjing'
}
}]);

}
}],
store : Ext.data.StoreManager.lookup('emptyStore'),
columns : [],
plugins : [Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit : 1,
listeners : {
beforeedit : function(editor, e, eOpts) {
var record = e.record;
console.log(record.raw.address.city)
var value = e.value;
if ('-' == value) {
return false;
} else {
return true;
}
},
edit : function(editor, e, eOpts) {
var record = e.record;
console
.log(record.raw.address.city = 'shanghai')
}
}

})],
height : 200,
width : 300,
renderTo : Ext.getBody()
});
})


参考:

http://docs.sencha.com/extjs/4.0.7/#!/api/Ext.data.Store-method-loadRawData
http://www.sencha.com/forum/showthread.php?192809
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: