我有一个传入的产品对象数组,如下所示:
[{
"id" : 16,
"price" : 500,
"quantity" : 2000,
"denomination" : "case",
"denominationPlural" : "cases",
"product" : {
"id" : 14,
"description" : "This is the text description for product 14."
}
}, {
"id" : 18,
"price" : 500,
"quantity" : 1,
"denomination" : "study",
"denominationPlural" : "studies",
"product" : {
"id" : 17,
"description" : "This is a text description for product 17."
}
}]
产品是产品乘以数量换取价格。
现在我想在 GridPanel 中显示这些产品,但还要在这些行中包含嵌套的产品信息。这是我之前的做法:
Ext.define('Offering', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'number'},
{name: 'price', type: 'number'},
{name: 'quantity', type: 'number'},
{name: 'denomination', type: 'string'},
{name: 'denominationPlural', type: 'string'},
{name: 'product.description', type: 'string'},
]
});
var offeringStore = Ext.create('Ext.data.Store', {
autoDestroy: true,
model: 'Offering',
proxy: {
type: 'ajax',
url: '/offerings',
reader: {
type: 'json',
root: 'success'
}
},
autoLoad:true
});
var offeringGrid = Ext.create('Ext.grid.Panel', {
store: offeringStore,
columns: [{
header: 'id',
dataIndex: 'id'
}, {
header: 'price',
dataIndex: 'price'
}, {
header: 'quantity',
dataIndex: 'quantity'
}, {
header: 'denomination',
dataIndex: 'denomination'
}, {
header: 'description',
dataIndex: 'product.description'
},
};
这效果很好。然后,在这个过程中的某个地方(包括从 ExtJS 4.2.1 升级到 ExtJS 5.1.1)和使用 Sencha Architect,它崩溃了。
问题 1:Sencha Architect 阻止在产品模型中创建“product.description”条目,提示“.”特点。但是,如果您将其创建为“whateveryouwant”,则可以进入模型字段并将其重命名为“product.description”。
问题 2:解决“.”之后问题并运行应用程序,“product.description”列的单元格为空白。
问题 3:javascript 控制台产生零错误。传入的数据看起来不错。
我应该如何让这些嵌套数据显示出来?
最佳答案
我的做法很简单。只需将 mapping
属性添加到模型即可:
{
name: 'product.description',
type: 'string',
mapping : 'product.description'
}
不需要渲染器
。
关于javascript - 如何在 ExtJS(和 Sencha 架构师)的 GridPanel 中显示嵌套对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30734083/