用于在道场创建dijit的三元逻辑

时间:2012-10-12 18:20:28

标签: javascript

在if / else中这很简单,但是我试图进入三元逻辑以及它是如何工作的。这是我第一次尝试。

 if(condtion == true){
                        var showProtected = new dijit.form.CheckBox({                                                               
                            checked: true
                        })else{
                            showProtected = new dijit.form.CheckBox({
                            checked: false
                            });     
                        });
                         showProtected.placeAt("showProtected", "first");   
}

我累了但不行:

showProtected = (condition == true) ? new dijit.form.CheckBox({                                                             
                            checked: true
                        }) : new dijit.form.CheckBox({
                            checked: false
                        });     
                         showProtected.placeAt("showProtected", "first");   

2 个答案:

答案 0 :(得分:1)

你可以让它更简单,只是说:

var showProtected = new dijit.form.CheckBox({
  checked: (condition == true)
});

答案 1 :(得分:0)

 if(condition){                     
                        var pro = new dijit.form.CheckBox({
                            id: "true",                                 
                            title: "Checked",
                            checked: true
                        });                         

                    }else{
                        var pro = new dijit.form.CheckBox({
                            id: "false",                                
                            title: "Unchecked",
                            checked: false
                        });             
                    }
                    pro.placeAt("showCheckbox", "first");
相关问题