道场:具有默认值的继承 - 混合不会发生
-
21-08-2019 - |
题
我希望声明一个从现有 dojo 类继承的新 dojo 类,但我自己选择该类属性的默认值。(用户仍然可以覆盖这些值。)
我正在声明我自己的版本 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" />
这确实会创建一个 FilteringSelect
与所需的 promptMessage
(这意味着超类正确获取了参数),但是 hasDownArrow
是 true
(与我的默认 mixin 相反)和 store
是 null
(Firebug 控制台报告说 storeUrl
是 ”undefined
").
我究竟做错了什么?
解决方案
哎呀!我真的有事情在他们头上。我找到了正确的方法。以下作品:
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});
}
}
);
不隶属于 StackOverflow