DOJO中的声明式或程式化方法? [英] Declarative or programatic approach in DOJO?

查看:106
本文介绍了DOJO中的声明式或程式化方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建DOJO组件时,我们应该更喜欢声明式方法和编程方法吗?

While creating DOJO Components when should we prefer declarative approach and programatic approach?

推荐答案

完全取决于您的需求和偏好。如果您有设计师而不是需要添加Dojo小部件的程序员,则可能最好使用声明式标记。但是,如果您坚持HTML标记通过w3c验证,则需要使用编程方法。

Depends entirely on your needs and preferences. If you have designers rather than programmers needing to add Dojo widgets, it may be preferable for them to use the declarative markup. However, if you insist that the HTML markup pass w3c validation, you'll want to use the programmatic approach instead.

我更喜欢编程方法,因为它允许我打包整个表单作为JavaScript对象,并创建实例化和验证其小部件的方法。 注释后的附录:我通常会使用其表单输入和dojo / dijit小部件作为其属性创建一个JavaScript对象,所以我可以将它们引用为 this.startDateTextBox,this.titleInlineEditor 等等。我处理javascript对象构造函数中dojo小部件的实例化。

I prefer the programmatic approach because it allows me to wrap an entire form as a javascript object and create methods to instantiate and validate its widgets. Addendum after comment: I will usually create a javascript object with its form inputs and dojo/dijit widgets as its properties so I can refer to them as this.startDateTextBox, this.titleInlineEditor etc. I handle the instantiation of the dojo widgets in the javascript object constructor function.

如果使用多个类似的小部件,可以有一个如果您声明持有其初始化设置的对象并以编程方式加载它们,而不是以声明方式声明每个标记的所有共享属性,则可以节省键入错误。我更喜欢编程实例的另一个原因是,我可以在实际启动窗口小部件之前根据不同的条件更改实例化参数,而不是像服务器端一样来更改标记。

If you use multiple similar widgets, there can be a savings in typing errors if you declare objects that hold their initialization settings and load them programmatically instead of declaring all the shared properties in the markup for each one declaratively. Another reason I prefer programmatic instantiation is that I can change the instantiation parameters based on different conditions before actually starting up a widget more easily than if I had to do it server-side to change the markup.

这篇关于DOJO中的声明式或程式化方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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