dojo:具有默认值的继承 - 混合不会发生

发布于 2024-07-12 09:24:59 字数 1566 浏览 7 评论 0原文

我希望声明一个从现有 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" />

这确实会创建一个带有所需 FilteringSelectFilteringSelect 。 code>promptMessage (这意味着超类正确获取了参数),但是 hasDownArrowtrue (与我的默认 mixin 相反)并且 storenull(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 to false (rather than the standard true) and
  • there's an extra possible property storeUrl which allows me to connect the FilteringSelect to the corresponding QueryReadStore.

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮光之海 2024-07-19 09:24:59

哎呀! 我真的有事情在他们头上。 我找到了正确的方法。 以下作品:

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});
      }
   }
);

Oops! I really had things on their head. I found the right way around. The following works:

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});
      }
   }
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文