Inheritance dojo:具有默认值的继承-mixin不';不会发生
我希望声明一个新的dojo类,该类继承自现有的dojo类,但使用我自己为该类的属性选择的默认值。(用户仍然可以覆盖这些值。) 我声明自己版本的Inheritance dojo:具有默认值的继承-mixin不';不会发生,inheritance,constructor,dojo,mixins,declare,Inheritance,Constructor,Dojo,Mixins,Declare,我希望声明一个新的dojo类,该类继承自现有的dojo类,但使用我自己为该类的属性选择的默认值。(用户仍然可以覆盖这些值。) 我声明自己版本的dijit.form.FilteringSelect,以便: hasDownArrow属性默认为false(而不是标准的true)和 还有一个额外的属性storeUrl,允许我将FilteringSelect连接到相应的QueryReadStore 以下是我所做的,但没有成功: dojo.provide("my.FilteringSelect"); d
dijit.form.FilteringSelect
,以便:
属性默认为hasDownArrow
(而不是标准的false
)和true
- 还有一个额外的属性
,允许我将storeUrl
连接到相应的FilteringSelect
QueryReadStore
dojo.provide("my.FilteringSelect");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojox.data.QueryReadStore");
dojo.declare(
"my.FilteringSelect",
[
dijit.form.FilteringSelect, /* base superclass */
{ hasDownArrow:false, storeUrl:"/" } /* mixin */
],
{
constructor: function(params, srcNodeRef){
console.debug("Constructing my.FilteringSelect with storeUrl "
+ this.storeUrl);
this.store = new dojox.data.QueryReadStore({url:this.storeUrl});
}
}
);
比如说,我试图在HTML中以声明方式生成这样一个版本的my.FilteringSelect
:
<input type="text" id="birthplace" name="birthplace"
promptMessage="Start typing, and choose among the suggestions"
storeUrl="/query/regions"
dojoType="my.FilteringSelect" />
这确实会使用所需的promptMessage
创建一个FilteringSelect
(这意味着超类正确地获取了参数),但是hasDownArrow
是true
(与我的默认mixin相反),store
是null
(Firebug控制台报告storeUrl
是“未定义的
”)
我做错了什么?哎呀!我真的让他们头疼。我找到了正确的方法。以下方法很有效:
dojo.provide("my.FilteringSelect");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojox.data.QueryReadStore");
dojo.declare(
"my.FilteringSelect",
dijit.form.FilteringSelect,
{
hasDownArrow : false,
storeUrl : "/",
constructor: function(params, srcNodeRef){
dojo.mixin(this, params);
console.debug("Constructing my.FilteringSelect with storeUrl "
+ this.storeUrl);
this.store = new dojox.data.QueryReadStore({url:this.storeUrl});
}
}
);
哎哟!我真的让他们头疼。我找到了正确的方法。下面的作品:
dojo.provide("my.FilteringSelect");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojox.data.QueryReadStore");
dojo.declare(
"my.FilteringSelect",
dijit.form.FilteringSelect,
{
hasDownArrow : false,
storeUrl : "/",
constructor: function(params, srcNodeRef){
dojo.mixin(this, params);
console.debug("Constructing my.FilteringSelect with storeUrl "
+ this.storeUrl);
this.store = new dojox.data.QueryReadStore({url:this.storeUrl});
}
}
);