我是一个Dojo新手,我正在尝试创建一个自定义模板化的Dojo小部件。使用attributeMap将自定义Dojo窗口小部件属性映射到HTML textarea元素的文本节点的正确方法是什么?我希望能够在声明性地创建自定义Dojo小部件时设置textarea的值。 例如 ... ...
<script type="text/javascript">
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.addOnLoad(function() {
dojo.declare("MyCustomWidget", [dijit._Widget, dijit._Templated], {
txtComment: "undefined",
templateString: "<div><textarea dojoAttachPoint="contentNode" rows='10' cols='20'></textarea></div>",
attributeMap: {
txtComment: {
node: "contentNode", // what should the correct mapping be to allow the
type: "innerHTML" // setting of txtComment declaratively above in the body?
},
}
});
dojo.parser.parse();
});
</script>
答案 0 :(得分:1)
我在这里找到的好东西。可能我不完全正确。 1)首先我们必须在dojo.addOnLoad()之前使用dojo.declare(“MyCustomWidget”,[dijit._Widget,dijit._Templated]语句,这将导致代码如下所示
<body><div dojoType="abcd.MyCustomWidget" txtComment="decl value"></div></body>
<script type="text/javascript">
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.declare("MyCustomWidget", [dijit._Widget, dijit._Templated], {
txtComment: "undefined",
templateString: "<div><textarea dojoAttachPoint="contentNode" rows='10' cols='20'></textarea></div>",
attributeMap: {
txtComment: {
node: "contentNode", // what should the correct mapping be to allow the
type: "innerHTML" // setting of txtComment declaratively above in the body?
},
}
});
dojo.addOnLoad(function() {
// for programatically creating widget.
new abcd.MyCustomWidget({txtComment:'what ever'},"adcd")
});