1

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

模板“车辆控制

<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 中格式化代码?我需要用什么代码标签来包围我粘贴在这里的代码?

4

1 回答 1

2

在Widget 生命周期buildRendering的一部分之前,模板中的 Widget 不会被实例化。

您可能希望等到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 的引用复制到其他变量——您应该始终能够从小部件本身获取对这些属性的引用。

于 2013-05-09T12:06:50.817 回答