How to disable a single option in a dijit.form.Select?

戏子无情 提交于 2020-01-04 02:27:05

问题


I created 2 Dojo dropdowns using dijit.form.Select that I am populating with 2 ArrayLists. When a user selects an option from the 1st dropdown, I would like an option in the 2nd dropdown to disable. I can't seem to figure out how to do this. Is it possible to disable a single option from the dropdown programatically? Something like...

if(this.dropDown1.get("value") == "FirstOption") {
    //this.dropDown2.get("value", "AnotherOption").set("disabled", true); ??
}

回答1:


Try to retrieve the value you want from dropDown2, and set its disabled property to true, directly (there is no setter, it's just a plain javascript object). Then call dropDown2.startup() to make the changes on the UI. Example :

require(["dojo/_base/array"], 
function(array) { 

    var self = this,

    opt = array.filter(
                  self.dropDown2.options, 
                  "return item.value == '" + self.dropDown2.get("value") + "'"
              ).pop(); 

    opt.disabled = true;

    this.startup();

});


来源:https://stackoverflow.com/questions/17951503/how-to-disable-a-single-option-in-a-dijit-form-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!