gpt4 book ai didi

extjs - EXT.JS 循环遍历 store 并在 items 数组中生成组件

转载 作者:行者123 更新时间:2023-12-04 18:47:21 24 4
gpt4 key购买 nike

我正在尝试使用存储在我的商店中的数据将一堆组件添加到我的容器中。我想遍历我的商店记录并输出一个标签/面板/等来显示数据。

这就是我现在循环的方式:

  initComponent: function () {
//Create a container for each array, then in that container,
//create a label and wrapping panel, then add the items to the wrapping panel
this.store = Ext.create('Ext.data.Store', {
model: 'MyProject.model.ItemArray',
data: []
});
Ext.apply(this, {
items: [
this.store.each(function() {
{
xtype:'label', text:
'test'
}
})
]
});

this.callParent(arguments);
}

但是,当然,作为我的 EXTJS 菜鸟,这行不通。我将不胜感激您可以提供的任何建议和最佳实践提示,以使其正常工作。

我的模型 ItemArray 包含项目。我需要遍历我的 ItemArrays 存储并制作容器,然后遍历 ItemArray 中的 Items,用 Items 填充这些容器。

谢谢大家!

最佳答案

您需要先加载您的商店,然后在商店回调中生成您的标签。

var me = this;
me.store.load(function(records) {
Ext.each(records, function(record) {
//Add a container for each record
me.add({
xtype: 'container',
items: [] //your labels here
});
});
});​

在您的示例中,您的商店尚未填充。它还异步加载,所以会有一点延迟。

关于extjs - EXT.JS 循环遍历 store 并在 items 数组中生成组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12164560/

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