在输入表单中使用combos时,我遇到了一个有趣的问题。我的表单包含从json存储获取数据的组合。当添加新记录时,它工作得很好,但是当打开表单来编辑现有记录时,有时id显示为选中而不是它的值(例如:有5而不是"apple")。我认为它试图在完成组合加载之前设置该值。
我检查了Combo store count,它返回0,这意味着在加载combo之前已经完成了选择。我尝试在加载事件和触发select事件中设置值,但不起作用,当我在加载存储时重新选择另一个记录时,效果很好
我也看到了这个帖子,但它没有给出可行的答案ExtJS combo setting problem
有没有什么方法可以设置它的文本?
有没有人能给我正确的答案?
发布于 2010-08-16 15:40:40
您是否在comboBox中使用标准的ExtJs方法setValue来设置值?
检查是否在Ext.onReady(...)中设置了值;
或者,如果通过ajax加载值,则可以使用带有回调的更新方法作为第三个参数(参见http://dev.sencha.com/deploy/dev/docs/ -> ComboBox)
发布于 2010-08-17 13:24:54
var partyType_store = new Ext.data.Store(
{
autoLoad: false,
autoDestroy: true,
// Note that I have renamed the web service proxy class
proxy: new Ext.data.HttpProxy({
url: accounts.webService + '/GetType',
// ASP.NET WebService call in GET format
headers: {
'Content-type': 'application/json'
}
}),
fields: ['AccountTypeId', 'AccountTypeName'],
listeners {
load: function() {
Ext.getCmp('cmbPartyType').setValue(Ext.getCmp("txtId").getValue());
Ext.getCmp('cmbPartyType').fireEvent("select");
}
}
},
// Combo is defined as
{
xtype: 'combo',
width: 150,
fieldLabel: 'Party Type',
name: 'PartyType',
id: 'accounts-cmbPartyType',
store: partyType_store,
displayField: 'PartyType',
valueField: 'PartyTypeId',
hiddenName: 'PartyTypeId',
mode: 'local', // important property when using store
typeAhead: true,
triggerAction: 'all',
selectOnFocus: true,
allowBlank: true,
forceSelection: true
}我在事件上加载组合存储,比如按钮单击事件
Ext.getCmp('cmbPartyType').getStore().load(); //this calls combo load event如果我在存储中设置autoLoad=true,它可以正常工作,但实际上,在用户按下按钮之前,我不想一开始就加载存储以减少流量
发布于 2010-08-17 21:59:51
为什么模式设置为local而不是remote?您是否使用了FireBug来确保从ASP服务发送的数据格式正确?
我不太清楚你对这两种商品的期望是什么:
valuefield:'PartyTypeId‘<--这是一个数字还是acode? 5?
displayField:'PartyType‘<--这是一个数字还是代码?苹果?
https://stackoverflow.com/questions/3491159
复制相似问题