这有点难以解释,所以我正在尽力,如果我的问题含糊不清,请要求更清楚。
我正在使用商店中的选项填充选择字段。该表单显示在用户单击我的常规 ListView 中的一行时获得的详细 View 上。这一切都完美无缺。
我在 Push() 中使用 record.data 将相关数据传递到详细 View ,并使用初始化监听器捕获此数据并填充详细 View 上的一些项目(标题、表单等)。
我的选择字段有一个更改监听器,用于在字段更改后执行 ajax 请求。发生的情况是,我的选择字段首先从商店加载选项,然后调用初始化监听器。
每次加载 View 时都会产生 ajax 请求。因为我的初始化监听器更改了选择字段以将另一个选项显示为事件状态,所以选择字段认为某些内容已更改并触发更改监听器。
将选择字段选项设置为事件而不触发更改监听器的最佳方法是什么?
带有更改监听器的选择字段:
xtype: 'selectfield',
itemId:'groundtype',
displayField: 'ground_name',
valueField: 'ground_id',
store: 'groundTypeStore',
listeners: {
change: function (data) {
// execute ajax request on change
}
}
表单面板(detailview)初始化监听器
listeners:
{
initialize: function(){
var value = this.config.record;
if(value != null){
this.down('#groundtype').setValue(value.groundtype);
}
}
}
提前致谢!
最佳答案
您可以在使用suspendEvents设置值时暂停字段的事件。功能:
var field = this.down('#groundtype');
field.suspendEvents();
field.setValue(value.groundtype);
field.resumeEvents(true);
请注意,您需要将 true
传递给 resumeEvents
为了丢弃排队的事件。
关于javascript - Selectfield 监听器在 View 初始化时触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21882647/