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

0

うーん、jsonはそうですか?

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

そして、あなたはdijit.form.ComboBoxin variable cobox、あなたのdojo.data.ItemFileReadStorein 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 に答える