1

TLDR:如何使 value() 在 jsbin 链接中的条件下正确响应?http://jsbin.com/pikoye/edit

我正在使用 Kendo UI 的 ComboBox 并且遇到了一个边缘案例,我希望有人可以帮助我。我使用组合框来显示 MRU 命令列表。通过下面所述的步骤,如果用户选择了一个命令,但随后改变了主意或对其进行了编辑,则结果value()仍然具有所选项目的值。

  1. 用鼠标选择列表中的一个项目
  2. 光标现在位于文本框中文本的末尾
  3. 选择所有文本
  4. 输入“某事”并按下enter
  5. 警报将显示所选项目的值,但显示“某物”的文本。

我已经尝试过其他按键事件来尝试更改时间,但没有任何运气。它发生在 IE11、Chrome 和 Firefox 中。我也尝试过不同版本的 KendoUI。我们希望能够让用户按下enter提交他们的选择,所以必须保留。我的解决方案是使用该text()值,该值目前有效,但似乎value()应该有效。

更新:我想要的是Value()返回“某物”,而不是您之前选择的索引。我可以Text()与索引的文本值进行比较,但似乎这是不必要的比较。要查看我希望看到的值,请单击“自定义”按钮。

4

1 回答 1

0

I have provided a possible solution in this jsbin for you http://jsbin.com/vupagekizu/1/

Hopefully I have understood what it is you are after.

Basically all I have done is added a Select event onto the combobox for you that checks to see if the index of the selected item is greater than -1 i.e. an item in the list and if it is then the system stores it in a global variable for you to access. In order to get all the properties of the item I have selected the dataItem associated with the selected item.

var selectedValue = null;


 select: function(e)
    {
      if(e.item.index() > -1)
        {
          selectedValue = this.dataItem(e.item.index());
      alert(selectedValue);
        }
      else 
        {
          //do nothing.
        }          
    }
于 2014-10-22T20:16:36.493 回答