[英]OpenUI5: JS views vs. XML views
We're currently evaluating SAP's OpenUI5 in the context of a new project. 我们目前正在一个新项目的背景下评估SAP的OpenUI5。
While most examples and tutorials tend to construct views using XML, out of personal preference I'd choose Javascript for the task. 虽然大多数示例和教程倾向于使用XML构建视图,但出于个人偏好,我会选择Javascript来完成任务。 However I haven't poked around in OpenUI5 long enough to identify any specific strengths for either approach. 但是,我没有在OpenUI5中找到足够长的时间来确定这两种方法的任何特定优势。
Are there any disadvantages in using JS? 使用JS有什么缺点吗? Or advantages even? 还是有优势呢?
Many Thanks! 非常感谢!
Update: 更新:
I agree with SDD64's answer. 我同意SDD64的回答。 After using both approaches in parallel for a while, I can add the following pros and cons to the list: 在并行使用这两种方法一段时间后,我可以在列表中添加以下优缺点:
XML advantages: XML优势:
XML disadvantages: XML缺点:
I am also a fan of JS based views. 我也是基于JS的观点的粉丝。 Possible (dis)Advantages are in my eyes: 可能(dis)优点在我眼中:
Advantages for JS JS的优点
Disadvantages for JS JS的缺点
** Update 2015-06-18 ** **更新2015-06-18 **
With the current OpenUI5 1.28 supporting conditions in XML views and the recently previewed 1.30 supporting binding for dynamic loading of XML fragments , I felt the need to update my answer. 利用XML视图中当前的OpenUI5 1.28支持条件以及最近预览的1.30支持动态加载XML片段的绑定 ,我觉得有必要更新我的答案。
With those new features, XML views gained a "healthy" amount of flexibility. 借助这些新功能,XML视图获得了“健康”的灵活性。 Making them, for me, more attractive when compared to JS based view. 对于我来说,与基于JS的视图相比,使它们更具吸引力。
It's all in the eyes of the developer. 这一切都在开发人员的眼中。 Some devs will prefer to write html5 like (xml) views, other will prefer the feeling in control with the js views. 有些开发人员更愿意编写html5之类的(xml)视图,其他人则更喜欢用js视图控制感觉。 Small disadvantage of the xml views is the extra step to convert them to js code. xml视图的一个小缺点是将它们转换为js代码的额外步骤。 They should be a bit (neglitable) slower. 它们应该有点(可忽略)慢。
You can build your pages dynamically with XML-Views: 您可以使用XML-Views动态构建页面:
Controller 调节器
sap.ui.controller("my.own.controller", {
onInit: function () {
var jsonData = {
simpsons: [
{name: "Marge", gender: "female"},
{name: "Homer", gender: "male"},
{name: "Bart", gender: "male"},
{name: "Lisa", gender: "female"},
{name: "Maggi", gender: "female"},
{name: "Snowball1", gender: "female"},
{name: "Ruprecht", gender: "male"}
]
};
var oModel = new JSONModel(suggJSON);
this.setModel(oModel, "myJsonModel");
},
});
View : 查看 :
<core:View
xmlns:core="sap.ui.core"
xmlns:m="sap.m"
xmlns="sap.ui.commons"
xmlns:html="http://www.w3.org/1999/xhtml"
>
Content of Model:
<m:VBox items="{myJsonModel>/simpsons}">
<Button text="{myJsonModel>name} visible="{= ${myJsonModel>gender} === 'male'}"/>
<Text text="{myJsonModel>name} visible="{= ${myJsonModel>gender} === 'female'}"/>
</m:VBox>
</core:View>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.