在dojo中编程方面与声明式创建的小部件之间的区别? [英] Difference between programmatically vs declaratively created widgets in dojo?

查看:134
本文介绍了在dojo中编程方面与声明式创建的小部件之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 以编程方式

  2. 声明性

要以编程方式创建小部件,我们将使用JavaScript,而我们将在HTML标签中使用dojo属性。



有人可以解释一下他们之间有什么区别?



哪一个是首选,为什么?

解决方案

差异



dojo-data-props ,还有一些其他属性,如值,标题,...。因此,您创建的DOM节点实际上作为某种占位符。



当您通过编写JavaScript代码创建小部件时,您将必须提供要附加的DOM节点但是最大的区别是它不会从该DOM节点复制HTML属性。这里的DOM节点只能用作容器,而不是占位符。






首选



没有解决方案主要是首选,它通常取决于您的应用程序的要求,以及您认为最干净的开发方式。



就我个人而言,我喜欢声明式标记,因为它是用户界面的一部分。但是,你可以去你想要的那样远。我已经看到人们以声明的方式创建商店和小部件事件处理程序,但是我个人更喜欢用JavaScript编写它们,因为它们不是用户界面的一部分。



还有其他原因可能会改变您创建窗口小部件的方式。例如,声明式标记的最大缺点之一是您需要解析页面(例如使用 parseOnLoad )。这通常比以编程方式创建小部件更慢。您可以通过只解析某些DOM节点来改进它,但是您必须编写其他代码(并不是更快)。



只是一个小笔记;这并不意味着声明的方式是缓慢的。这只是一个额外的操作,应该执行,因此,它有点慢,但可能最终用户甚至不会看到差异。



声明性的优点但是,当加载页面时,最终用户能够看到占位符。如果您选择正确的占位符(例如,< select> for dijit / form / FilteringSelect dijit / form / ComboBox ),最终用户至少会看到一些东西。如果您以编程方式创建所有内容,最终用户将看到一个空白页面,直到执行JavaScript代码。



因此,如果性能是其中一个要求,那么您可以选择创建他们以编程方式如果你喜欢分离代码,其中表示层与业务逻辑分离,那么我建议使用声明式的方式。



但最后,两个解决方案很好。


I know in dojo we can create any widgets in two ways,

  1. programmatically
  2. declaratively

To create widgets programmatically we'll use JavaScript, whereas for declaratively we'll use dojo attributes in HTML tags.

Can someone explain me what are the differences between them?

which one is mostly preferred and why?

解决方案

Difference

Well, there are certain differences between both ways. In the declarative way, all configuration is based upon HTML attributes like dojo-data-props but also some other attributes like the value, title, ... . So the DOM node you create actually serves as some kind of placeholder.

When you create widgets by writing JavaScript code, you will have to provide the DOM node you will attach it too, but the biggest difference is that it will not copy the HTML attributes from that DOM node. The DOM node here only serves as a container, not a placeholder.


Preferred

There is no solution that is mostly preferred and it usually depends on the requirements of your application and what you think is the cleanest way of developing.

Personally I like the declarative markup because in the end it's a part of the user interface. However, you can go as far as you want. I've seen people creating stores and widget event handlers in a declarative way too, but I personally prefer to write them in JavaScript since they're not a part of the user interface.

There are also other reasons that might change the way you would create widgets. For example, one of the biggest drawbacks of declarative markup is that you need to parse the page (for example with parseOnLoad). This usually is slower than creating the widgets programmatically. You can improve it by only parsing certain DOM nodes, but then you have to write additional code (and it still isn't faster).

Just a small note; this doesn't mean that the declarative way is slow. It's just an extra operation that should be executed and thus, it's a bit slower but chances are that the end user will not even see the difference.

An advantage of the declarative way however is that, when loading the page, the end user is able to see the placeholder. If you pick the right placeholder (for example, a <select> for dijit/form/FilteringSelect and dijit/form/ComboBox), the end user will at least see something. If you create everything programmatically, the end user will see a blank page until the JavaScript code is executed.

So if performance is one of the requirements, then you could choose creating them programatically. If you like to have seperation of code where the presentation layer is seperated from the business logic, then I would recommend using the declarative way.

But in the end, both solutions are good.

这篇关于在dojo中编程方面与声明式创建的小部件之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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