0

我正在尝试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;
    }
} 
4

1 回答 1

0

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

可能有一种更特定于 dojo 的方式来做到这一点,但我对此无能为力!

于 2013-08-07T17:01:17.670 回答