我在 DOJO 中有一个小部件,我可以使用它设置属性
registry.byId('1831').set('title', 'xxx PROP 已更新');
- 我会根据属性更改更新 HTML。
知道如何做吗?
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
'dijit/_AttachMixin',
"dojo/text!./templates/Button.html",
"dojo/dom-style",
"dojo/_base/fx",
"dojo/_base/lang",
"dojo/on",
"dojo/mouse",
"require"
], function (declare, _WidgetBase, _TemplatedMixin, _AttachMixin, template, domStyle, baseFx, lang, on, mouse, require) {
// private members
return declare([_WidgetBase, _TemplatedMixin, _AttachMixin], {
// public properties
templateString: template,
ntvType: 'Button',
baseClass: "ntvButton",
title: 'Title here',
// set properties doho.stateful
_setTitleAttr: function (value) {
console.log("Setting value of title to " + value);
this._set("title", value);
},
postCreate: function () {
var domNode = this.domNode;
},
});
});
<div data-ntv-type="${ntvType}" class="${baseClass}">
<button type="button">${title}</button>
</div>
最佳答案
dijit 提供了一种内置机制将 widget 属性映射到 dom 节点属性。这是通过定义为散列的自定义 setter 来完成的。例如:
//属性
名称:“未知”,
_setNameAttr: { 节点: "nameNode", 类型: "innerHTML"}
关于javascript - 如何在 DOJO 中将属性映射到 DOM 节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27444504/