Extjs正在使用更新的无线电项目数组重新加载无线电组
Extjs reloading radiogroup with updated radio items array
我有一个包含formPanel
的Ext.Window
。formPanel有一个radiogroup
项,该项加载radioItemsArray
。最初,我基于来自myRadioStore
的数据创建每个radioItem
,并在formpanel中映射到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
谢谢!
没有任何东西将存储直接绑定到无线电组。您可以向商店添加一个侦听器,然后使用update
侦听器以程序方式添加新的商店无线电。
未测试的代码,但应该足够接近。
// 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
}]
});
在radioGroup
的情况下,对表单调用布局/渲染不起作用。因此,每次更新myRadioStore
时,都需要从表单中删除radiogroup
,从myRadioStore
创建一个radio
数组,然后在form
中重新添加无线电g
组数组。
类似于:
Ext.getCmp('my-form').remove(Ext.getCmp('allRadiosID'), true);
// recreate `radioItemsArr[]` array of radios from updated `radioItemsArr` and add it back to form
Ext.getCmp('my-form').add(new Ext.form.RadioGroup({
anchor: '0',
autoHeight: true,
id: 'allRadiosID',
items: [
radioItemsArr
]
});
相关文章:
- 数据表 AJAX 筛选器重新加载数据
- 如何在新加载的页面上执行(下拉)操作
- 根据上一个选项卡的选择器重新加载选项卡
- 获得“中止,因为不接受 0”并使用反应热加载器重新加载整页
- 咕噜咕噜的手表:实时加载重新加载落后 1 步....
- 如何为新加载的元素提供JQuery UI工具提示
- 如何在新加载的页面上使用相同的JavaScript代码(通过重定向)
- 使用PHP或Javascript检测页面刷新或新加载
- 砌体重新加载&reloadItems不起作用
- 如何使javascript计时器重新加载
- 如何获取新加载的图像's width / naturalWidth
- 列出并调用firefox扩展中新加载的选项卡中的js函数
- 旋转器重新加载图像似乎在覆盖层后面
- AJAX调用后,新加载的CSS选择器对jQuery.ech()不可用
- jQuery砌体-砌体重新加载后调用方法
- 如何向所有查看器重新加载页面
- 如何打开子浏览器窗口,然后在新加载的子浏览器页面上执行脚本以单击其中的链接
- 如何选择新加载 html 的元素
- 在 jQuery 的 ajax.load() 之后,无法将元素附加到新加载的内容中
- 我怎么能有一个花哨的盒子一样的弹出体加载,但与cookie不连续加载重新加载