Dojox / mvc /型号范围 [英] Dojox/mvc/at model scope

查看:148
本文介绍了Dojox / mvc /型号范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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 。有三件事情谈到在这里设置范围:


  1. 运行 Dojo解析器 parser.parse(rootNode,{propsThis:scopeObj}); code>这个在 data-dojo-props 指定的对象。以这种方式 data-dojo-props =widgetProp:at(this,'scopeObjProp')指向 scopeObj

  2. 小部件模板中 data-dojo-props =widgetProp:at(this,'widgetsInTemplateProp')指向窗口小部件模板实例中的属性。

  3. 相对数据绑定通过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:

  1. Running Dojo parser with parser.parse(rootNode, {propsThis: scopeObj}); you can make this in data-dojo-props the specified object. In this way data-dojo-props="widgetProp: at(this, 'scopeObjProp')" points to a property in scopeObj.
  2. In widgets-in-template, data-dojo-props="widgetProp: at(this, 'widgetsInTemplateProp')" points to a property in widgets-in-template instance.
  3. Relative data binding makes target property in a widget up in DOM referred via "rel:" special syntax. Setting an object to the target property there, like registry.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆