大家好,
本博客介绍了Sap UI5中绑定选项的基本概念和演示。
使用的工具:
Sap UI5提供了三个绑定选项
属性绑定:将控件的属性绑定到模型。
属性绑定可以通过三种方式完成。
通用编码实现属性绑定。
在花括号内在构造函数中
var oControl=新建sap.ui.commons.TextView({
controlProperty:"{modelProperty}"
});
按绑定属性方法
"controlProperty","modelProperty");
按路径
var oControl=newsap.ui.commons.TextView({
controlProperty:{path:"modelProperty"}
});
属性绑定演示:
在这个演示中,我们将使用所有三个属性绑定选项来显示表的属性
步骤1:在Eclipse中创建Sap UI5应用程序项目
,File–>New–>other并选择"SAP UI5 Application Development"–>Application Project并单击next按钮。
提供项目名称并单击next按钮。
第2步:在createcontent方法下实现以下代码。
var aGalaxy=[
{"Planet":"Mercury","Diameter":"5100","Gravity":0.40},
{"Planet":"Venus","直径":"12600","重力":0.90},大数据数据库,
{"行星":"地球","直径":"12800","重力":1.00},
{"行星":"火星","直径":"6900","重力":0.40},
{"行星":"木星","直径":"143600","重力":2.70},
{"行星":"土星","直径":"120600","重力":1.20},
{"行星":"天王星","直径":"53400","重力":1.00},
{"Planet":"Pluto","Diameter":"12700","Gravity":1.40}];
var oModel=newsap.ui.model模型.json.JSONModel文件({
value:aGalaxy
});
//Create instance of table control
var oTable=newsap.ui.table表.表格({
标题:"行星的物理特征",
可见行数:8,
第一可见行数:0,
宽度:"500px"
});
//将模型绑定到表控件
oTable.setModel(oModel);
oTable.bindRows行("/值");
可旋转.placeAt("内容");
记住要包括图书馆"sap.ui.table表"在索引.html
New–>other,然后选择"SAP UI5应用程序开发"–>应用程序项目,点击下一步按钮。
提供项目名称,点击下一步按钮。
第2步:在createcontent方法下实现以下代码。
//Create instance of JSON Model
var oModel=newsap.ui.model模型.json.JSONModel文件({
值:
[{"index":"0","level":"Success","description":"Performance is good"},
{"index":"1","level":"Warning","description":"Service not available."},
{"index":"2","level":"Error","description":"Record not found"}]
};
//Bind Model to core
sap.ui.getCore().集合模型(oModel);
//Create template of message type
var oRowTemplate=新建sap.ui.commons.Message({
文本:"{description}",
类型:"{level}"
});
//Create RowRepeater and bind Message template
var oRowRepeater=newsap.ui.commons.RowRepeater();
oRowRepeater.bindRows行("/值",或模板);
oRowRepeater.placeAt公司("内容");
结果:
右键点击索引.html选择"在服务器上运行"选项
元素绑定
通过元素绑定可以实现要绑定到模型中某个对象的元素。控件的相对绑定的上下文由元素控件表示。为了显示所选标题信息的详细列表,您需要使用此父子绑定。
元素绑定演示:
在本演示中,我们将显示来自本地json模型的父表weekdays中的菜单,淘客是什么,并根据父表中的选择更改子表中的值元素绑定
第一步:在Eclipse中创建Sap UI5应用程序项目
,File–>New–>other并选择"SAP UI5 Application Development"–>Application Project并单击next按钮。
提供项目名称并单击next按钮
第2步:在createcontent方法下实现以下代码。
var oModel=Newsap.ui.model模型.json.JSONModel文件({
工作日:
[{"日":"周一","无餐":"2","id":"1"},
{"day":"星期二","无餐":"1","id":"2"},
{"day":"星期三",北京大数据公司,"无餐":"2","id":"3"},
{"day":"星期四","无餐":"2",易淘客,"id":"4"},
{"day":"星期五","无餐":"1","id":"5"},
膳食:
{"MealNo":"1","dayId":"1","items":"炸薯条"},
{"MealNo":"2","dayId":"1","items":"法式吐司"},
{"MealNo":"3","dayId":"2","items":"炸薯条配汉堡"},
{"MealNo":"4","dayId":"3","items":"热狗"},
{"MealNo":"5","dayId":"3","items":"炸薯条"},
{"MealNo":"6","dayId":"4","items":"甜甜圈"},
{"MealNo":"7","dayId":"4","items":"热狗"},
{"MealNo":"8","dayId":"5","items":"法式吐司"},
]
});
sap.ui.getCore().setModel(oModel);
//Table with weekdays
var oTable=新建sap.ui.table表.Table({
width:"100%",
title:"Weekdays",
visibleRowCount:5,
selectionMode:sap.ui.table表.选择模式。单,
});
oTable.addColumn(新建)sap.ui.table表.列({
标签:新建)sap.ui.commons.Label({text:"Weekday"}),
模板:新建sap.ui.commons.TextField({value:"{day}"})
});
oTable.addColumn(新建)sap.ui.table表.列({
标签:新建)sap.ui.commons.Label({text:"禁止用餐"}),
模板:新建sap.ui.commons.TextField({value:"{no_dies}"})
});
oTable.bindRows行("/工作日");
可旋转.placeAt("母公司");
//餐食显示
var oTable2=新sap.ui.table表.Table({
title:"用餐",什么是数据中台,
visibleRowCount:3,
width:"100%",
选择模式:sap.ui.table表.选择模式。单,
可编辑:false
});
oTable2.addColumn(新建)sap.ui.table表.列({
标签:新建)sap.ui.commons.Label({text:"餐"}),
模板:新建sap.ui.commons.TextField({value:"{MealNo}"})
});
oTable2.addColumn(新建)sap.ui.table表.列({
标签:新建)sap.ui.commons.Label({text:"Description"}),
模板:新建sap.ui.commons.TextField({value:"{items}"})
});
oTable2.bindRows("/feeds");
oTable2.placeAt("child");
记住要包括图书馆"sap.ui.table表"在索引.html