gpt4 book ai didi

javascript - 如何在 ExtJS(和 Sencha 架构师)的 GridPanel 中显示嵌套对象?

转载 作者:行者123 更新时间:2023-11-29 16:58:02 29 4
gpt4 key购买 nike

我有一个传入的 Offering 对象数组,如下所示:

[{
"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 5.1.1(从 ExtJS 4.2.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'
}

不需要renderer

关于javascript - 如何在 ExtJS(和 Sencha 架构师)的 GridPanel 中显示嵌套对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30734083/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com