这是我的模型:
data: i
0: i
data: Object
events: Object
hasListeners: k
id: "region-ext-record-344"
index: 0
internalId: "ext-record-344"
modified: Object
phantom: false
raw: Array[2] // i want to get those two elements one displayField, another valueField
0: "01"
1: "Region 1"
length: 2
__proto__: Array[0]
store: i
stores: Array[1]
__proto__: Object
1: i
2: i
3: i
length: 4
__proto__: Array[0]
如果你愿意的话我可以发布代码!
我尝试阅读商店,例如:
store: regionStore
,但它向我显示一个空盒子,其中有 4 个空行,等于我商店中的商品数量,然后我尝试这样做 store: regionStore.data.items
现在它向我显示 [object object]
行,我完全明白为什么,但找不到解决方案。我对所有 ExtJs 的东西都很陌生,但我正在使用 ExtJs 4。
我的模型看起来像这样:
Ext.regModel('region', {
fields: [
{name: 'id', type: 'integer'},
{name: 'name', type: 'String'}
});
我的商店看起来像这样:
var regionStore = new Ext.data.ArrayStore({
id: 'regionStore',
model: 'region',
data: MyDesktop.GridWindow.getRegionData() //that is data from ajax response
});
我的组合框:
{
xtype: 'combobox',
value: "region",
store: regionStore,
width: 135,
id: 'regionCombo'
editable: false
}
最佳答案
您已将您的问题标记为 extjs 4.2,但您的代码是旧式的并且未遵循建议。我强烈建议您阅读该手册,尤其是 MVC 的介绍。
Ext.regModel 从版本 4.0.0 开始已弃用。按如下方式更改代码并将其保存到文件 app/model/Region.js 中:
Ext.define('MyApp.model.Region', {
extends: 'Ext.data.Model',
fields: [
{name: 'id', type: 'integer'},
{name: 'name', type: 'string'}
]
});
在文件 app/store/Regions.js 中:
Ext.define('MyApp.store.Regions', {
extends: 'Ext.data.ArrayStore',
//id: notice that id is no longer necessary
model: 'Region',
//data: you load the store from the server, so the data is loaded automatically
autoLoad: true
})
你的组合框变成:
xtype: 'combobox',
value: 'region',
store: 'Regions',
width: 135,
id: 'regionCombo',
editable: false,
valueField: 'id',
displayField: 'name'
我在 4.2 之前从未使用过 extjs,但版本 4 中引入的更改似乎很重要。采用新范式可能很困难。但我确信它从根本上简化了您的代码。您绝对不会后悔这一步。
另外,随着 5.0 版本的发布,我认为是时候养成新习惯并抛弃 ExtJs 2.0 编码风格了。
关于javascript - 我想从 Extjs 4 的存储中读取数据,但它显示 [object object],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25053829/