javascript databinding - Dojo changing scope of data dojo attach point -
can specify/change scope of data-dojo-attach-point other current widget?
eg. have templated widget called parent. in template have widget called child1. nested in child1, have widgets. want bind these nested widgets child1 rather parent.
edit:
<div data-dojo-type="somecontainer" data-dojo-attach-point="parent"> <div data-dojo-type="somepane" data-dojo-attach-point="child1"> <span data-dojo-attach-point="(i want bound somepane)"></span> </div> </div>
i'd bind "span" somepane without having go through somecontainer.
separate span it's own widget , can add them parent this.
parent template contains content panes
<div style="width: 100%; height: 100%;"> <div data-dojo-type="dijit/layout/layoutcontainer" style="width: 100%; height: 100%" data-dojo-attach-point="mainnode"> <div data-dojo-type="dijit/layout/contentpane" data-dojo-props="region:'top'" > <div > <!--some content--> </div> </div> <div data-dojo-type="dijit/layout/contentpane" data-dojo-props="region:'center'" id="center"> <div data-dojo-attach-point="centernode"></div> </div> </div> </div>
in postcreate method of parent widget create new instance of child , attach parent
define([ "dojo/_base/declare", "dijit/_widgetbase", "dijit/_templatedmixin", "dijit/_widgetsintemplatemixin", "dojo/text!./templates/parent.html", "somepath/childwidget", 'dojo/domready!' ], function ( declare, _widgetbase, _templatedmixin, _widgetsintemplatemixin, parenttemplate, childwidget ) { return declare([_widgetbase, _templatedmixin, _widgetsintemplatemixin], { templatestring: parenttemplate, postcreate: function () { this.inherited(arguments); var mychild = new childwidget(); mychild.placeat(this.centernode); mychild.startup(); } }); });
then because span inside it's own widget, might have template looks this
<div> <span data-dojo-attach-point="spannode"></span> </div>
so span attach point decoupled parent. can directly reference 'spannode' within widget created span.
declaratively, in childwidget contains span can give give class name this
return declare("childwidget", [_widgetbase, _templatedmixin, _widgetsintemplatemixin], { ...
and in parent template instead of using attach point attach widget use data-dojo-type this
<div data-dojo-type="dijit/layout/contentpane" data-dojo-props="region:'center'" id="center"> <div data-dojo-type="childwidget"><!--child widget attached here--></div> </div>
Comments
Post a Comment