从ExtJs中的组合框获取完整的模型对象?

Jam*_*hon 15 extjs extjs4

如果我有一个商店支持的组合框选择在ExtJS 4下触发事件,我该如何获得由该选择表示的完整对象?

Rus*_*rri 22

通常,您可以findRecordByValue在组合框上使用该方法:

combobox.on('change', function(combobox, newValue, oldValue) {

   // Get the old and the new records.
   // NOTE: The underlying store is not guaranteed to 
   //       contain an associated record.
   var oldRecord = combobox.findRecordByValue(oldValue);
   if (oldRecord) {
      // Do something...
   }

   var newRecord = combobox.findRecordByValue(newValue);
   if (newRecord) {
      // Do something...
   }
});
Run Code Online (Sandbox Code Playgroud)


Jam*_*hon 6

在发布我的问题后几乎立即想出来.

我的问题是我绑定了错误的事件,我使用'更改'而不是'选择'.

选择事件为您提供包含其中完整对象的记录.

  • 请注意,只有当值更改时才会触发`select`事件,因为用户单击了列表中的选项.如果以编程方式调用`setValue`,则只会触发`change`. (5认同)