简体   繁体   中英

Dojo: option[selected ='selected'] not working for run-time change

I am working on a multi-select box and found

var count = dojo.query("option[selected ='selected']", dojo.byId('select_id')).length;

Always returns whatever original from the page(database) but yet what user selected at run-time. I am running on Dojo 1.6. So how can I count number of selected options from multi-select box AT RUN-TIME?

I made a page that shows users and the groups they are in. Here is some of the code. I had to rip some stuff out to make it concise. The last line of code answers the question. It returns an array with the checked values.

// Programattically create the select.
var _groups = new dojox.form.CheckedMultiSelect({
    multiple : true,
    class : "cssThing"
}, "groups" + _userNumber);

// Fill the CheckedMultiSelect boxes with unchecked data.
var tempArray = new Array();
dojo.forEach(groupList, function(row, index) {
    tempArray.push({
        value : row.value,
        label : row.label,
        selected : false,
    });
});
_groups.addOption(tempArray);

// Populate the CheckedMultiSelect with an array.
var tempArray = [];
dojo.forEach(user.groups, function(row) {
    tempArray.push(String(row.groupName));
});
_groups.set('value', tempArray);

// Get the CheckedMultiSelect values as an array.
_groups.get('value');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM