在自定义Dojo小部件中,如何正确设置attributemap?
我是一个Dojo新手,正在尝试创建一个定制的模板化Dojo小部件。使用attributeMap将自定义Dojo小部件属性映射到HTML textarea元素的文本节点的正确方法是什么?我希望能够在声明式创建自定义Dojo小部件时设置textarea的值。 例如 ... ...在自定义Dojo小部件中,如何正确设置attributemap?,dojo,Dojo,我是一个Dojo新手,正在尝试创建一个定制的模板化Dojo小部件。使用attributeMap将自定义Dojo小部件属性映射到HTML textarea元素的文本节点的正确方法是什么?我希望能够在声明式创建自定义Dojo小部件时设置textarea的值。 例如 ... ... <script type="text/javascript"> dojo.require("dijit._Widget"); dojo.require("dijit._Templated");
<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>
require(“dijit._小部件”);
dojo.require(“dijit._模板化”);
dojo.addOnLoad(函数(){
declare(“MyCustomWidget”,[dijit.\u Widget,dijit.\u模板化]{
txtComment:“未定义”,
templateString:“”,
属性映射:{
TXT评论:{
node:“contentNode”,//正确的映射应该是什么才能允许
键入:“innerHTML”//在正文中声明性地设置txtComment?
},
}
});
parser.parse();
});
我在这里找到了很多好东西。也许我不完全正确。
1) 首先,我们必须在dojo.addOnLoad()之前使用dojo.declare(“MyCustomWidget”,“dijit.\u Widget,dijit.\u Templated”)语句,这将产生如下所示的代码
<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>
<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")
});
require(“dijit._小部件”);
dojo.require(“dijit._模板化”);
declare(“MyCustomWidget”,[dijit.\u Widget,dijit.\u模板化]{
txtComment:“未定义”,
templateString:“”,
属性映射:{
TXT评论:{
node:“contentNode”,//正确的映射应该是什么才能允许
键入:“innerHTML”//在正文中声明性地设置txtComment?
},
}
});
dojo.addOnLoad(函数(){
//用于以编程方式创建小部件。
新的abcd.MyCustomWidget({txtComment:'what ever'},“adcd”)
});
我在这里发现了很多好东西。可能是我不完全正确。
<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>
1) 首先,我们必须在dojo.addOnLoad()之前使用dojo.declare(“MyCustomWidget”,“dijit.\u Widget,dijit.\u Templated”)语句,这将产生如下所示的代码
<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>
<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")
});
require(“dijit._小部件”);
dojo.require(“dijit._模板化”);
declare(“MyCustomWidget”,[dijit.\u Widget,dijit.\u模板化]{
txtComment:“未定义”,
templateString:“”,
属性映射:{
TXT评论:{
node:“contentNode”,//正确的映射应该是什么才能允许
键入:“innerHTML”//在正文中声明性地设置txtComment?
},
}
});
dojo.addOnLoad(函数(){
//用于以编程方式创建小部件。
新的abcd.MyCustomWidget({txtComment:'what ever'},“adcd”)
});
<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>