定义model:
var that = this;
var xmModel = new JSONModel();
this.setModel(xmModel, "xmModel");
this.getRouter().getRoute("Home").attachPatternMatched(this._onRouteMatched, this);
var TMKCModel = new JSONModel({
data: []
});
TMKCModel.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);
this.setModel(TMKCModel, "TMKCModel");
var oSearchModel = new JSONModel({
Werks: null,
Xhuowei: null,
Lgort: null,
Exidv: null,
Ztype: true,
});
oSearchModel.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);
this.setModel(oSearchModel, "searchModel");
var tijiaomodel = new JSONModel({
click: false
});
tijiaomodel.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);
this.setModel(tijiaomodel, "tijiaomodel");
model赋值:
that.getModel("searchModel").setProperty("/Xhuowei", "");
that.getModel("searchModel").setProperty("/Ztype", true);
that.getModel("searchModel").setProperty("/Lgort", "");
that.getModel("searchModel").setProperty("/Exidv", "");
that.getModel("tijiaomodel").setProperty("/click", false);
清空model:
var TMModelclear = that.getModel("TMKCModel");
TMModelclear.setData({
data: []
});
that.getModel("TMKCModel").refresh();
错误展示
MessageBox.error('请扫描检验批!');
直接更改model里面第一组数的值:
that.getModel("filterModel").setProperty("/0/Vemng",vemng2);
跳转页面:
this.getRouter().navTo("sPack", {
oOperationData: JSON.stringify(oOperationData)
});
model中需要将this改为that。
manifest文件中如果有传参需要在routes和targets中配置。
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "com.shunyu.xbcbhb.view",
"controlId": "app",
"controlAggregation": "pages",
"async": true
},
"routes": [{
"name": "Home",
"pattern": "",
"target": [
"home"
]
}, {
"name": "sunPack",
"pattern": "sunPack/{oOperationData}",
"target": [
"sunPack"
]
}, {
"name": "print",
"pattern": "print/{Customerid}/{oOperationData}/{printitem}",
"target": [
"print"
]
}, {
"name": "sPack",
"pattern": "sPack/{oOperationData}",
"target": [
"sPack"
]
}],
"targets": {
"home": {
"viewType": "XML",
"viewLevel": 1,
"viewName": "Home"
},
"sunPack": {
"viewType": "XML",
"viewLevel": 2,
"viewName": "SunPack"
},
"print": {
"viewType": "XML",
"viewLevel": 2,
"viewName": "Print"
},
"sPack": {
"viewType": "XML",
"viewLevel": 2,
"viewName": "Spack"
}
}
BUTTON样式:
<Button text="{i18n>return}" width="100%" press="navtoReurn" type="Emphasized"></Button>
循环数组
item.forEach(function(oItem) {
oItem.selected = (oItem.Matnr === sInputValue);
});
消息提醒并返回
if (searchdata.gcvalue == null) {
MessageToast.show(“请选择工厂”, {
at: “Center Center”
});
return;
}
添加公共部分
删除行项目
VIEM:
<Column hAlign="Right" width="8rem">
<Text text="{i18n>cz}" />
</Column>
<Button icon="sap-icon://delete" press="onDel" />
方法:
onDel: function (oEvent) {
var oBundle = this.getView().getModel("i18n").getResourceBundle();
var that = this;
var sPath = oEvent.getSource().getBindingContext("filterModel").getPath();
var oHuNumber = oEvent.getSource().getBindingContext("filterModel").getProperty(sPath).ztm;
MessageBox.confirm(oBundle.getText("QDSC") + oHuNumber + oBundle.getText("XM"), {
title: "Confirm",
styleClass: "sapUiSizeCompact",
actions: [sap.m.MessageBox.Action.YES,
sap.m.MessageBox.Action.NO
],
emphasizedAction: sap.m.MessageBox.Action.YES,
textDirection: sap.ui.core.TextDirection.Inherit,
onClose: function(oAction) {
if (oAction === sap.m.MessageBox.Action.YES) {
// eslint-disable-next-line radix
var oIndex = parseInt(sPath.split('/')[sPath.split('/').length - 1]);
var oItemModel = that.getModel("filterModel");
var oItemData = oItemModel.getProperty("/data");
oItemData.splice(oIndex, 1);
oItemModel.refresh();
} else {
sap.m.MessageToast.show(oBundle.getText("CANCLESC"));
}
}
});
},
**i18n**
cz=操作
QDSC=你确定要删除
XM=这项吗?