Dojox / mvc /型号范围 [英] Dojox/mvc/at model scope
问题描述
在dojox / mvc包中使用状态对象时,声明性示例似乎在全局命名空间(没有var关键字定义)中具有目标模型。这违反了好的Javascript设计的一般做法,污染了全球的命名空间,更不用说使用不同的模型了,而且混乱了。我的问题是,这个声明在()的范围是什么,以及如何使用一个位于某个上下文/范围内的模型?
http: //dojotoolkit.org/reference-guide/1.9/dojox/mvc.html#id6
其中<一个href =http://dojotoolkit.org/reference-guide/1.9/dojox/mvc/at.html> dojox / mvc / at API通常用于data-dojo-props 。有三件事情谈到在这里设置范围:
- 运行 Dojo解析器与
parser.parse(rootNode,{propsThis:scopeObj});
code>这个在 data-dojo-props 指定的对象。以这种方式data-dojo-props =widgetProp:at(this,'scopeObjProp')
指向scopeObj $ c中的属性$ c>。
- 在小部件模板中,
data-dojo-props =widgetProp:at(this,'widgetsInTemplateProp')
指向窗口小部件模板实例中的属性。 -
相对数据绑定通过rel:特殊语法引用DOM中的小部件中的
target
属性。将对象设置为目标
属性,如registry.byId(scopeWidget)。set(target,{First:John ,最后:Doe});
在下面的示例中,将填充< input>
中的值:< script type =dojo / require> at:dojox / mvc / at< / script>
< div id =scopeWidget
data-dojo-type =dijit / _WidgetBase
data-dojo-props =target:{}>
< div>
首先:
< input data-dojo-type =dijit / form / TextBox
data-dojo-props =value:at('rel:','First') >
< / div>
< div>
最后:
< input data-dojo-type =dijit / form / TextBox
data-dojo-props =value:at('rel:','Last') >
< / div>
< / div>
希望这有帮助。 b
$ b
最佳,
Akira
When using a Stateful object in the dojox/mvc package, the declarative examples seems to have the target model in the global namespace (defined without the "var" keyword). This violates the general practices of good Javascript design by polluting the global namespace, not to mention making the use of different models difficult and messy.
My question is, what's the scope of that declarative at() and how would one use a model that lies inside a certain context/scope?
http://dojotoolkit.org/reference-guide/1.9/dojox/mvc.html#id6
Where dojox/mvc/at API is typically used in is data-dojo-props. Three things comes to my mind talking about setting "scope" there:
- Running Dojo parser with
parser.parse(rootNode, {propsThis: scopeObj});
you can makethis
in data-dojo-props the specified object. In this waydata-dojo-props="widgetProp: at(this, 'scopeObjProp')"
points to a property inscopeObj
. - In widgets-in-template,
data-dojo-props="widgetProp: at(this, 'widgetsInTemplateProp')"
points to a property in widgets-in-template instance. Relative data binding makes
target
property in a widget up in DOM referred via "rel:" special syntax. Setting an object to thetarget
property there, likeregistry.byId("scopeWidget").set("target", {First: "John", Last: "Doe"});
in below example, will populate the value in<input>
:<script type="dojo/require">at: "dojox/mvc/at"</script> <div id="scopeWidget" data-dojo-type="dijit/_WidgetBase" data-dojo-props="target: {}"> <div> First: <input data-dojo-type="dijit/form/TextBox" data-dojo-props="value: at('rel:', 'First')"> </div> <div> Last: <input data-dojo-type="dijit/form/TextBox" data-dojo-props="value: at('rel:', 'Last')"> </div> </div>
Hope this helps.
Best, Akira
这篇关于Dojox / mvc /型号范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!