data-dojo-attach-point不在相关的Custom Widget Class中解析的值

时间:2013-05-09 02:38:21

标签: javascript dojo

我为自定义小部件定义了以下模板(这只是一个示例,它不一定“工作”)

模板“ VehicleControl

<div>
    <div data-dojo-attach-point="carSelect" data-dojo-type="srcore.widget.input.Select" title="Select Car" required="true"></div>
    <div data-dojo-attach-point="wheelsSelect" data-dojo-type="srcore.widget.input.Select" title="Select Wheels" required="true"></div>
</div>

这是我的相关自定义小部件类,向您展示第一部分,直到我尝试引用附加点“carSelect”

define(["dojo/_base/declare",
    "dojo/_base/array",
    "dojo/_base/lang",
    "dojo/on",
    "dijit/_Widget",
    "dijit/_TemplatedMixin",
    "dijit/_WidgetBase",
    "dijit/_WidgetsInTemplateMixin",
    "./_InputWidgetMixin",
    "../secure/_SecureWidgetMixin",
    "sc/widget/input/Select" // our extension of the base digit seelct
],
    function (declare, array, lang, on, _Widget, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, _InputWidgetMixin, _SecureWidgetMixin)
    {
        return declare("srcore.widget.input.VehicleControl", [_WidgetBase, _InputWidgetMixin, _TemplatedMixin, _WidgetsInTemplateMixin, _SecureWidgetMixin],{

        _templateString: dojo.cache("srcore", "widget/templates/VehicleControl.html"),

        _carDropdown: null

        constructor: function() {
            this._parentWidgetNode = this.domNode;
            this._carDropdown =  this.carSelect;

...

问题是,当我在WebStorm(JetBrains编辑器)时,它显示this.carSelect没有解析。我不知道我在这段代码中缺少什么,以及为什么当我将_WidgetBase,_InputWidgetMixin,_TemplatedMixin,_WidgetsInTemplateMixin包含在继承中时,为什么这不会解决。

还不够吗?现在不应该解决吗?

我如何在Nabble中格式化代码?我需要使用哪些代码标签来包含我在此处粘贴的代码?

1 个答案:

答案 0 :(得分:2)

模板中的小部件在Widget lifecyclebuildRendering部分之前不会被实例化。

您可能希望等到生命周期的postCreate部分开始使用模板中的小部件:

define([...], function(...){
  return declare("srcore.widget.input.VehicleControl", [_WidgetBase, _InputWidgetMixin, _TemplatedMixin, _WidgetsInTemplateMixin, _SecureWidgetMixin],{

    _templateString: dojo.cache("srcore", "widget/templates/VehicleControl.html"),

    _carDropdown: null

    postCreate: function(){
      //make sure any parent widget's postCreate functions get called.
      this.inherited(arguments);

      //can now work with this.domNode and this.carSelect
    }

});

我也不确定为什么你只是简单地将this.domNode和this.carSelect的引用复制到其他变量 - 你应该始终能够从widget本身获得对这些属性的引用。