问题
I'm using Dojo 1.5 to create a dijit.form.Select with some data from a datastore. The issue I'm finding is that I want the select to show the elements ordered by the identifier, but the select is ginving them ordered by the label. How can I avoid this behaviour?. Another issue I'm finding is that when I set the store, I initialized the store to select one of the elements, but it is selecting the first one. The code is a follows:
dojo.require("dijit.form.Select");
dojo.require('dojo.data.ItemFileReadStore');
dojo.addOnLoad(function(){
var boxContent = {"identifier":"idBox","items":[{"accessLevel":"FULL_ACCESS",
"boxName":"My Documents","boxType":"PERSONAL","idBox":1512,"numberFiles":9,
"userDisplayName":"Jose Luis Martinez Avial","userName":"MIAMARA"},
{"accessLevel":"FULL_ACCESS","boxName":"12312312","boxType":"PERSONAL",
"idBox":17100,"numberFiles":0,"userDisplayName":"Jose Luis MartinezAvial",
"userName":"MIAMARA"}],"label":"boxName"};
var myStore = new dojo.data.ItemFileReadStore({data: boxContent });
var boxCombo= new dijit.form.Select({
name: 'select2' }).placeAt(dojo.body());
boxCombo.setStore(myStore,1512);
})
It is available in http://jsfiddle.net/m9ucX/1/
Thanks for your help.
回答1:
Just in case anyone comes looking, this question was also asked (and has been answered) on the dojo-interest mailing list:
I think you'll get what you want if you just set sortByLabel: false on your Select.
Source:
http://mail.dojotoolkit.org/pipermail/dojo-interest/2011-February/052328.html
来源:https://stackoverflow.com/questions/4910783/how-to-change-order-of-elements-in-a-dijit-form-select