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

时间:2023-01-15 18:47:29

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.)

我希望声明一个继承自现有dojo类的新dojo类,但是我自己选择了类属性的默认值。 (用户仍然可以覆盖这些值。)

I am declaring my own version of the dijit.form.FilteringSelect such that:

我正在声明我自己的dijit.form.FilteringSelect版本,这样:

  • the hasDownArrow property defaults to false (rather than the standard true) and
  • hasDownArrow属性默认为false(而不是标准的true)和

  • there's an extra possible property storeUrl which allows me to connect the FilteringSelect to the corresponding QueryReadStore.
  • 有一个额外的可能属性storeUrl,它允许我将FilteringSelect连接到相应的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:

说,我尝试在HTML中以声明方式生成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").

这确实会创建一个带有所需promptMessage的FilteringSelect(这意味着超类正在获取params),但hasDownArrow为true(与我的默认mixin相反)并且存储为null(并且Firebug控制台报告storeUrl为“undefined” “)。

What am I doing wrong?

我究竟做错了什么?

1 个解决方案

#1


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

#1


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