#仿照代码一写的,但是代码二实现不了,想知道具体原因,谢谢!
#代码一如下:
sap.ui.define([
"ZUI_PUS_SHOW2/controller/BaseController"
], function(BaseController) {
return BaseController.extend("ZUI_PUS_SHOW2.controller.View1", {
onValueHelpRequest: function(oEvent) {
var that = this;
var oODataModel = this.getView().getModel();
var sPath = "/werksF4Set"; //实体对象
oODataModel.read(sPath, {
success: function(oData, oResp) {
var owerksF4et = {
werksF4et: oData.results
};
var aReturnData;
for (var a in owerksF4et) {
aReturnData = owerksF4et[a];
}
var aResultRow = []; //数组
var oResultRow = {};
for (var i = 0; i < aReturnData.length; i++) {
oResultRow = {};
oResultRow["title"] = aReturnData[i].Werks;
oResultRow["des"] = aReturnData[i].Name1;
aResultRow.push(oResultRow);
}
that.setModel(new sap.ui.model.json.JSONModel({
title: '选择工厂',
list: aResultRow
}), "f4list");
that.onShowF4();
}
});
},
onShowF4: function() {
if (!this.byId('f4')) {
this.oF4 = sap.ui.xmlfragment(this.getView().getId(), "ZUI_PUS_SHOW2.fragment.WerksValueHelp", this.getView().getController());
this.getView().addContent(this.oF4);
}
this.oF4.open();
}
});
});
代码二如下:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel",
"sap/ui/core/routing/History",
"sap/ui/model/Filter",
"sap/ui/model/Sorter",
"sap/ui/model/FilterOperator",
"sap/m/GroupHeaderListItem",
"sap/ui/Device",
"sap/ui/core/Fragment"
], function(Controller,JSONModel, History, Filter, Sorter, FilterOperator, GroupHeaderListItem, Device, Fragment) {
"use strict";
return Controller.extend("zaps_show.controller.View1", {
onValueHelpRequest: function(oEvent) {
var that = this;
var oODataModel = this.getView().getModel();
var sPath = "/werksF4Set";
oODataModel.read(sPath, {
success: function(oData, oResp) {
var owerksF4Set = {
werksF4Set: oData.results
};
var aReturnData;
for (var a in owerksF4Set) {
aReturnData = owerksF4Set[a];
}
var aResultRow = []; //数组
var oResultRow = {};
for (var i = 0; i < aReturnData.length; i++) {
oResultRow = {};
oResultRow["title"] = aReturnData[i].Werks;
oResultRow["des"] = aReturnData[i].Name1;
aResultRow.push(oResultRow);
}
that.setModel(new sap.ui.model.json.JSONModel({
title: '选择工厂',
list: aResultRow
}), "f4list");
that.onShowF4();
},
error: function(oData, oResp) {
sap.m.MessageToast.show("工厂数据读取失败");
}
});
},
onShowF4: function() {
if (!this.byId('f4')) {
this.oF4 = sap.ui.xmlfragment(this.getView().getId(), "Zaps_Show.fragment.WerksValueHelp", this.getView().getController());
this.getView().addContent(this.oF4);
}
this.oF4.open();
}
});
});
功能实现的效果图如下:
代码二一直报错显示不出来,原因我不明白,还请教教我,谢谢!