dojo:具有默认值的继承 - 混合不会发生
我希望声明一个从现有 dojo 类继承的新 dojo 类,但我自己选择该类属性的默认值。 (用户仍然可以覆盖这些值。)
我声明我自己的 dijit.form.FilteringSelect
版本,这样:
hasDownArrow
属性默认为false< /code> (而不是标准的
true
),并且- 还有一个额外的可能属性
storeUrl
,它允许我将FilteringSelect
连接到相应的>查询读取存储
。
这就是我所做的,但没有成功:
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
的 FilteringSelect
。 code>promptMessage (这意味着超类正确获取了参数),但是 hasDownArrow
是 true
(与我的默认 mixin 相反)并且 store
为 null
(Firebug 控制台报告 storeUrl
为“undefined
”)。
我究竟做错了什么?
I wish to declare a new dojo class inheriting from an existing dojo class, but with my own choice of default values for the class's properties. (The user can still override those values.)
I am declaring my own version of the dijit.form.FilteringSelect
such that:
- the
hasDownArrow
property defaults tofalse
(rather than the standardtrue
) and - there's an extra possible property
storeUrl
which allows me to connect theFilteringSelect
to the correspondingQueryReadStore
.
Here's what I did, without success:
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});
}
}
);
Say, I try to generate declaratively in the HTML such a version of my.FilteringSelect
:
<input type="text" id="birthplace" name="birthplace"
promptMessage="Start typing, and choose among the suggestions"
storeUrl="/query/regions"
dojoType="my.FilteringSelect" />
This will indeed create a FilteringSelect
with the desired promptMessage
(which means that the superclass is properly getting the params), but hasDownArrow
is true
(contrary to my default mixin) and the store
is null
(and the Firebug console reports that storeUrl
is "undefined
").
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哎呀! 我真的有事情在他们头上。 我找到了正确的方法。 以下作品:
Oops! I really had things on their head. I found the right way around. The following works: