如何在dijit / form / ComboBox中使用queryExpr

时间:2017-04-23 15:45:56

标签: javascript dojo dijit.form

我有Combobox dijit/form/ComboBox,我希望当用户开始输入组合框时会显示包含字母的结果。

例如,combox具有此值

  • 内布拉斯加
  • 南达科他州
  • 特拉华

当用户键入" D" 结果应该是

  • 南达科他州
  • 特拉华

1 个答案:

答案 0 :(得分:2)

简单地使用queryExpr: "*${0}*"来搜索组合选择项是否包含搜索关键字。

使用最后一个完整的样本:



require([
    "dojo/store/Memory", "dijit/form/ComboBox", "dojo/domReady!"
], function(Memory, ComboBox){
    var stateStore = new Memory({
        data: [
            {name:"", id:""},
            {name:"Nebraska", id:"NE"},
            {name:"South Dakota", id:"SD"},
            {name:"Delaware", id:"DE"},
            {name:"Test1", id:"T1"},
            {name:"Test2", id:"T2"},
            {name:"Test3", id:"T3"}
        ]
    });

    var ComboBox = new ComboBox({
        id: "filteringCombo",
        store: stateStore,
        queryExpr: "*${0}*",
        searchAttr: "name"
    }, "filterCombo").startup();
});

<script type="text/javascript">
  dojoConfig = {isDebug: true, async: true, parseOnLoad: true}
</script>

<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link href="//ajax.googleapis.com/ajax/libs/dojo/1.8.3/dijit/themes/claro/claro.css" rel="stylesheet"/>
<body class="claro">
  <div id="filterCombo"></div>
</body>
&#13;
&#13;
&#13;