我在DOJO中创建了一些自定义小部件。
我需要能够在对象初始化时覆盖窗口小部件上的一些属性,例如:new _labelWebpart('my value here');
知道该怎么做吗?
var widget2 = new _labelWebpart('my value here');
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dojo/text!./templates/label.html",
"dojo/dom-style",
"dojo/_base/fx",
"dojo/_base/lang",
"dojo/on",
"dojo/mouse",
"require"
], function (declare, _WidgetBase, _TemplatedMixin, template, domStyle, baseFx, lang, on, mouse, require) {
return declare([_WidgetBase, _TemplatedMixin], {
label: "Default text for label", // THIS VALUE SHOULD BE OVERWRITTEN WHEN PASSING ARGUMENT IN THE COSTRUCTOR
templateString: template,
baseClass: "Label",
postCreate: function () {
var domNode = this.domNode;
this.own(
);
}
});
});
答案 0 :(得分:3)
我建议查看构造函数属性:
return declare([_WidgetBase, _TemplatedMixin], {
label: "Default text for label",
templateString: template,
// other stuff of your declare here
constructor: function(override_arguments_here) {
// your init code here to override the label from your arguments
}
});
答案 1 :(得分:0)
构造函数是文件中的第一个执行点。声明骨架应如下:
return declare("fileNameIfHTMLIsDifferent", [.....], {
templateString: _templateString
....
, constructor: function(args) {
declare.safeMixin(this, args);
....
}
, postCreate: function() {
this.inherited(arguments);
....
},
startup: function() {
this.inherited(arguments);
}
});