gpt4 book ai didi

javascript - Extjs 使用更新的单选项目数组重新加载单选组

转载 作者:行者123 更新时间:2023-11-28 01:01:26 25 4
gpt4 key购买 nike

我有一个包含 formPanelExt.Window。 formPanel 有一个 radiogroup 项,它加载 radioItemsArray。最初,我根据 myRadioStore 中的数据创建每个 radioItem ,并映射到表单面板中的 radiogroup 。这工作正常,请参阅下面的代码:

this.radioItemsArr = [];
Ext.each(myRadioStore.data.items, function(itm, i, all) {
var radioItem = new Ext.form.Radio({
id : itm.data.dataId,
// custom radio label with text + images
boxLabel:
'<b>Data id:</b> ' + itm.data.dataId + '<br/>' +
'<b>Data:</b> ' + itm.data.dataDetail + '<br/>' +
'<p>' + '<img id style="imgStyle" src=\"' + itm.data.url + '\"/></p>',
name: 'radioName',
inputValue: itm.data.dataId ,
height: 'auto',
checked: false
});
this.radioItemsArr.push(radioItem);
}, this);

this.myForm = new Ext.form.FormPanel({
border: false,
id:'my-form',
frame : true,
layout : 'fit',
items: [{
autoScroll: true,
id: 'myFormId',
defaults: {
labelStyle: 'font-weight:bold;'
},
items: [{
title: 'Custom Title',
items: [{
// custom description text set on form load
id: 'descId',
style : { marginTop: '15px', border:'5px'}
}]
}, {
title: 'Select an item from below',
items: [{
anchor: '0',
autoHeight: true,
xtype: 'radiogroup',
hideLabels: true,
id: 'allRadiosID',
items: [
this.radioItemsArr
],
}]
}
],
}],
buttonAlign :'center',
buttons: [{
// save button
},{
// cancel button
}]
});

这将在第一次正确加载所有单选按钮。但是,当使用来自服务器的新数据更新 myRadioStore 时(当用户单击按钮时会发生这种情况),我希望我的表单面板使用新的单选按钮进行更新。因此,当更新 myRadioStore 时,我会删除 radioItemsArray 中的所有项目,然后通过循环遍历存储并推送到 radioItemsArr 来创建新的 radioItem 。我可以看到 radioItemsArr 有新的单选按钮选项。但是 formpanel 中的 radiogroup 没有刷新。

调用 Ext.getCmp('my-form').doLayout() 似乎不起作用。有什么想法/评论吗?

编辑:我使用的是 extjs 3.4

谢谢!

最佳答案

没有什么可以将商店直接绑定(bind)到 radio 组。您可以向商店添加一个监听器,并使用 update 监听器以编程方式添加新的商店 radio 。

未经测试的代码,但应该已经足够了。

// Add a listener to the store, this can be defined in the `listeners` property of the store config too.

myRadioStore.addListener('update', function () {
// get the radio group and remove all items
var radioGroup = Ext.getCmp('allRadiosID');
radioGroup.removeAll();
// call the function to renew the radio array.
getRadioArray();
radioGroup.add(this.radioItemsArr);
// Optionally update the container form too
Ext.getCmp('my-form').doLayout();
}, this);


this.radioItemsArr = [];

function getRadioArray() {
this.radioItemsArr = [];
Ext.each(myRadioStore.data.items, function (itm, i, all) {
var radioItem = new Ext.form.Radio({
id: itm.data.dataId,
// custom radio label with text + images
boxLabel:
'<b>Data id:</b> ' + itm.data.dataId + '<br/>' +
'<b>Data:</b> ' + itm.data.dataDetail + '<br/>' +
'<p>' + '<img id style="imgStyle" src=\"' + itm.data.url + '\"/></p>',
name: 'radioName',
inputValue: itm.data.dataId,
height: 'auto',
checked: false
});
this.radioItemsArr.push(radioItem);
}, this);
}

getRadioArray();

this.myForm = new Ext.form.FormPanel({
border: false,
id: 'my-form',
frame: true,
layout: 'fit',
items: [{
autoScroll: true,
id: 'myFormId',
defaults: {
labelStyle: 'font-weight:bold;'
},
items: [{
title: 'Custom Title',
items: [{
// custom description text set on form load
id: 'descId',
style: {
marginTop: '15px',
border: '5px'
}
}]
}, {
title: 'Select an item from below',
items: [{
anchor: '0',
autoHeight: true,
xtype: 'radiogroup',
hideLabels: true,
id: 'allRadiosID',
items: [this.radioItemsArr]
}]
}]
}],
buttonAlign: 'center',
buttons: [{
// save button
}, {
// cancel button
}]
});

关于javascript - Extjs 使用更新的单选项目数组重新加载单选组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25569242/

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