如何根据dojo中的单选按钮动态更改组合框的searchAttr?

时间:2013-08-07 15:09:16

标签: javascript dojo dojo-1.9

我正在尝试根据单选按钮更改组合框的searchAttr的值。这是我到目前为止的工作片段。

<html>

<head>
  <title>Test</title>


  <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dijit/themes/claro/claro.css">

  <script>
    dojoConfig = {
      parseOnLoad: true
    }
  </script>
  <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js"></script>


  <script type="text/javascript">
    require([
      "dojo/store/Memory", "dijit/form/ComboBox", "dojo/domReady!"
    ], function(Memory, ComboBox) {
      var infoStore = new Memory({
        data: [{
          "prop1": "a1",
          "prop2": "a2"
        }, {
          "prop1": "b1",
          "prop2": "b2"
        }, {
          "prop1": "c1",
          "prop2": "c2"
        }]
      });

      var comboBox = new ComboBox({
        id: "combo_id",
        name: "info",
        store: infoStore,
        searchAttr: "prop1"
      }, "combo_id");
    });
  </script>

</head>

<body class="claro">


  <div>
    <input type="radio" name="searchType" id="search_type_one" />
    <label for="search_type_one">Search Type One</label>

    <input type="radio" name="searchType" id="search_type_two" />
    <label for="search_type_two">Search Type Two</label>

  </div>

  <input id="combo_id" />
  <p>
    <button onClick="alert(dijit.byId('combo_id').get('value'))">Get value</button>
  </p>

</body>

</html>

这是我想要完成的伪代码

searchAttr: function (item){
    if (searchType.value == "one"){
        return item.prop1;
    } else if (searchType == "two"){
        return item.prop2;
    }
} 

1 个答案:

答案 0 :(得分:0)

执行此操作的方法是将onChange回调中的require事件处理程序绑定到input[name=searchType]之类的选择器,每次更改事件触发时更新comboBox.searchAttr

可能有更多针对dojo的方法,但我无能为力!