简体   繁体   English

无法在dojo中读取未定义的属性“set”

[英]Cannot read property 'set' of undefined in dojo

i'm using the set property for enabling and disabling the button based on the checkbox click..while compiling getting error like this. 我正在使用set属性来启用和禁用按钮,基于复选框click..while编译得到这样的错误。 "Cannot read property 'set' of undefined" can anyone please help.thanks in advance. “无法读取'未定义'属性''可以请任何人帮助。谢谢提前。

JS: JS:

if(dojo.byId('pickLstValChkbox').checked === false){
    dijit.byId('isK9Acccepted').set('disabled', true)
}
else{
    dijit.byId('isK9Acccepted').set('disabled', false)
}

HTML: HTML:

<input type="CHECKBOX" name="" dojoType='dijit.form.CheckBox' id="pickLstValChkbox" value="CONFIRM_CHECKED">
<button class="defaultButton" dojoType="dijit.form.Button" id="isK9Acccepted">Accept</button>

This issue occurs, when you are trying to access dijit controls before parsing. 当您尝试在解析之前访问dijit控件时,会发生此问题。 use dojo.parser.parse(); 使用dojo.parser.parse(); before doing anything. 在做任何事之前。 more details can befound here. 更多详细信息可以在这里找到。 https://dojotoolkit.org/reference-guide/1.6/dojo/parser.html https://dojotoolkit.org/reference-guide/1.6/dojo/parser.html

Also, which version of dojo are you using? 另外,您使用的是哪个版本的道场? Looks like you are using legacy way of coding. 看起来您正在使用传统的编码方式。 I would suggest you migrate to AMD style. 我建议你迁移到AMD风格。

First thing is to call parser.parse() ( create and render dijits ) 首先要调用parser.parse() (创建并渲染dijits)

Then to access your dijit you have to use dojo/ready to ensure that all dijit's are loaded and rendered 然后要访问你的dijit,你必须使用dojo/ready来确保加载和渲染所有dijit's

In your case you want that when the checkbox is checked (unchecked ), you enable (disable) the button so, you have to use a change event on the checkbox dijit 在您的情况下,当您选中复选框(未选中)时,您需要启用(禁用)按钮,因此,您必须在复选框dijit上使用change事件

note that modern dojo uses data-dojo-* [ type, event , id ]insted of dojoType or dojoEvent ... in its html attrib . 请注意,现代dojo在其html attrib中使用了dojoType or dojoEvent ...的data-dojo-* [type,event,id]。

here is a fiddle that may help you : Fiddle 这是一个可以帮助你的小提琴小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法设置/读取未定义的属性 - Cannot set/ read property of undefined 无法设置/读取未定义的属性 - cannot set/read property of undefined dojo / parser :: parse()错误TypeError:无法读取未定义的属性&#39;getAttribute&#39; - dojo/parser::parse() error TypeError: Cannot read property 'getAttribute' of undefined 无法在dojo / request / iframe帖子上读取未定义的属性“值” - Cannot read property 'value' of undefined" on dojo/request/iframe post Typescript TypeError:无法读取未定义的属性“ set” - Typescript TypeError: Cannot read property 'set' of undefined 无法读取 javascript 中未定义的属性“集” - Cannot read property 'set' of undefined in javascript 余烬:TypeError:无法读取未定义的属性“ set” - ember: TypeError: Cannot read property 'set' of undefined dojo / parser :: parse()error TypeError {stack:(...),message:“无法读取未定义的属性&#39;toString&#39;”} - dojo/parser::parse() error TypeError {stack: (…), message: “Cannot read property 'toString' of undefined”} 无法读取未定义的属性“ then” - Cannot read property 'then' of undefined 无法读取未定义的属性“ 0” - Cannot read property '0' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM