开发者

In a custom Dojo widget, how to set attributemap correctly?

I am a Dojo newbie and am trying to create a custom templated Dojo widget. What is the correct way to map a custom Dojo widget attribute to the text node of an HTML textarea element using an attributeMap? I would like to be able to set the value of the textarea while declaratively creating the custom Dojo widget. e.g. ... ...

<script type="text/javascript">
    dojo.require("dijit._Widget");
    开发者_StackOverflow社区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>


Nice things i found here. May be i'm not completely correct. 1) first we have to use dojo.declare("MyCustomWidget", [dijit._Widget, dijit._Templated], statement before the dojo.addOnLoad(), which will result in code like shown below

<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")

});

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜