1
    var xhrArgs = {
     url: "../Person/GetAll",
         handleAs: "json",
         preventCache: true,
       load: function (data, ioargs) {
            var jsonString = dojo.toJson(data)
            var dataStore = new dojo.store.Memory({ data:
            dojo.fromJson(jsonString) });
    var personCmb = dijit.byId('cmbSingers');
                        if (personCmb == null)
 {
     var cobox = new dijit.form.ComboBox({ id: "cmbSingers", name: "Name", store: dataStore, searchAttr: "Name" }, "cmbSingers");

                                cobox.startup();
                            }

     function cmbSingers_OnSelected() {

               alert(dijit.byId('cmbSingers').get('value')); **this return the Text, But I want to get Id of Select value**     

            }
4

2 回答 2

1

对于任何在 2016+ 年寻找解决方案的人......我遇到了同样的情况,并找到了一种从 Dojo ComboBox 获取所选选项值的方法。不要只使用 .value 或 .get('value'),而是使用 .item.value:

dijit.byId('someComboBox').item.value

.item 将返回一个像这样的对象供您使用: Object {id: "1", value: "1", name: "One"}

详细说明...假设您使用这样的选择来定义 ComboBox 的选项:

<select dojoType="dijit.form.ComboBox" id="someComboBox" maxlength="30">
   <option value=""></option>
   <option value="1">One</option>
   <option value="2">Two</option>
   <option value="3">Three</option>
</select>

假设您选择“一个”选项。
调用dijit.byId('someComboBox').value将返回"One",但调用dijit.byId('someComboBox').item.value将返回"1"

于 2016-08-29T16:01:29.320 回答
0

Mkay, json is like so?

{ identifier: 'Id', items: [ { Id: '1', name:'foo', age: 12 }, { Id: '2', name:'bar', age: 30 } ] }

And you have dijit.form.ComboBox in variable cobox, your dojo.data.ItemFileReadStore in variable store.

dojo.connect(cobox, "onChange", function() {

  var val = this.get("value"),
    id = "",
    matcher = new RegExp("^" + val + "$");

  dojo.some(store._arrayOfAllItems, function(item, idx) {

   if(matcher.test(store.getValue(item, "name")) {
      id = store.getValue(item, "Id");
      return true; // breaks .some loop
   }
  });

});
于 2012-05-13T15:58:17.490 回答