在JSONModel上使用参数路由时出现问题

2020-09-02 15:47发布

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


嗨,我是SAPUI5的新手,我一直在尝试学习如何使用参数将模型中的参数路由到另一个页面,因此一直遵循SAP演练的步骤,但是在我的原型上实现它并不幸运。 想知道是否有人可以告诉我我在做什么错? 我已经尝试了几种替代方法,但是似乎没有运气。

Table.controller.js

 sap.ui.define([
 " ./BaseController",
 'sap/ui/model/json/JSONModel',
 'sap/m/MessageToast'
 ],函数(BaseController,JSONModel,MessageToast){
 "使用严格";

 var TableController = BaseController.extend(" opensap.myapp.controller.Table",{


 onInit:函数(){
//在此示例上设置浏览的应用程序的演示模型
 var oModel = new JSONModel(" model/personas.json");
 this.getView()。setModel(oModel);
 this.getView()。byId(" idPersonaTable");

 },

 titlePress:函数(oEvent){
 this._showPersona(oEvent.getSource());
 },


 _showPersona:函数(oItem){
 MessageToast.show(oItem.getBindingContext()。getPath());
 var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
 oRouter.navTo("角色",{
 objectId:oItem.getBindingContext()。getPath()。substr(oItem.getBindingContext()。getPath()。length-1)//oItem.getBindingContext()。getProperty(" Name")
 });
 }
 });


 返回TableController;


 });
 

Persona.controller.js:

 sap.ui.define([
 " ./BaseController",
 'sap/ui/model/json/JSONModel',
 'sap/m/MessageToast',
 'sap/ui/core/routing/History'
 ],函数(BaseController,JSONModel,MessageToast,历史记录){
 "使用严格";


 var PageController = BaseController.extend(" opensap.myapp.controller.Persona",{




 onInit:function(){
 var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
 oRouter.getRoute(" persona")。attachPatternMatched(this._onObjectMatched,this);
 },

 _onObjectMatched:函数(oEvent){
 this.getView()。bindElement({
 路径:"/img/PersonaCollection/" + oEvent.getParameter(" arguments")。objectId,
         模特:"角色"
 });
 MessageToast.show(oEvent.getParameter(" arguments")。objectId);
 },


 onNavBack:function(){
 var sPreviousHash = History.getInstance()。getPreviousHash();


 如果(sPreviousHash!==未定义){
 history.go(-1);
 }其他{
 this.getRouter()。navTo(" Table",{},true);
 }
 }



 });

 返回PageController;


 });
 

Persona.view.xml:

 


 

 
 <标题
 text =" {Name}"
 level =" H2"/>

 



 

  
  
 




 


 
 

manifest.json:

 {
 " _version":" 1.3.0",
 " sap.app":{
 " _version":" 1.3.0",
 " id":" opensap.myapp",
 " type":"应用程序",
 " title":" {{appTitle}}",
 " description":" {{appDescription}}",
 " applicationVersion":{
 " version":" 1.0.0"
 }
 },
 " sap.ui":{
 " _version":" 1.3.0",
 " technology":" UI5",
 " deviceTypes":{
 "桌面":是的,
 "平板电脑":是的,
 "电话":正确
 },
 " supportedThemes":[
 " sap_bluecrystal"
 ]
 },
 " sap.ui5":{
 " _version":" 1.2.0",
 " rootView":{
 " viewName":" opensap.myapp.view.App",
 " type":" XML",
 " id":" app"
 },
 " autoPrefixId":是,
 "依赖关系":{
 " minUI5Version":" 1.34",
 " libs":{
 " sap.ui.core":{
 " minVersion":" 1.34.0"
 },
 " sap.m":{
 " minVersion":" 1.34.0"
 },
 " sap.ui.layout":{
 " minVersion":" 1.34.0"
 }
 }
 },
 " contentDensities":{
 "紧凑":是的,
 "舒适":是
 },
 "路由":{
 " config":{
 " routerClass":" sap.m.routing.Router",
 " viewType":" XML",
 " viewPath":" opensap.myapp.view",
 " controlId":" app",
 " controlAggregation":"页面",
 "异步":true
 },
 "路线":[
 {
 " pattern":"",
 " name":"表",
 "目标":[
 "表"
 ]
 },
 {
 " pattern":"角色/{objectId}",
 " name":"角色",
 "目标":[
 "角色"
 ]
 }
 ],
 "目标":{
 "表格":{
 " viewName":"表格",
 " viewId":"表格",
 " viewLevel":1
 },
 "角色":{
 " viewName":" Persona",
 " viewId":"角色",
 " viewLevel":2
 }
 }
 }
 }
 }
 

personas.json(前2个元素):

 {
 " PersonaCollection":[
 {
 "名称":" Abaddon",
 " arcana":"判决",
 "级别":74,
 "统计信息":[51、38、58、43、39],
 " elems":[" ab"," ab","-","-","-","-"," wk"," wk","-"," ab"],
 "技能":{
 "吸收物理":79,
 "死神":0,
 " Gigantomachia":80,
 " Makarakarn":0,
 "精神流失":0,
 "生存技巧":77
 }
 },
 {
 "名称":" Agathion",
 " arcana":"战车",
 "级别":3,
 "统计信息":[3,4,5,7,3],
 " elems":["-"," rs","-","-"," rs"," wk","-","-","-","-"]],
 " skills":{" Baisudi":0," Dia":0," Dodge Elec":8," Lunge":4," Rakukaja":6," Zio":0},
 "个性":" Timid"
 },
 。
 。
 。

该视图是一种非常原始的视图,因为我仅使用它来测试路由是否目前有效。

有什么我想念的吗? 感谢您的关注和事先的帮助。

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


嗨,我是SAPUI5的新手,我一直在尝试学习如何使用参数将模型中的参数路由到另一个页面,因此一直遵循SAP演练的步骤,但是在我的原型上实现它并不幸运。 想知道是否有人可以告诉我我在做什么错? 我已经尝试了几种替代方法,但是似乎没有运气。

Table.controller.js

 sap.ui.define([
 " ./BaseController",
 'sap/ui/model/json/JSONModel',
 'sap/m/MessageToast'
 ],函数(BaseController,JSONModel,MessageToast){
 "使用严格";

 var TableController = BaseController.extend(" opensap.myapp.controller.Table",{


 onInit:函数(){
//在此示例上设置浏览的应用程序的演示模型
 var oModel = new JSONModel(" model/personas.json");
 this.getView()。setModel(oModel);
 this.getView()。byId(" idPersonaTable");

 },

 titlePress:函数(oEvent){
 this._showPersona(oEvent.getSource());
 },


 _showPersona:函数(oItem){
 MessageToast.show(oItem.getBindingContext()。getPath());
 var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
 oRouter.navTo("角色",{
 objectId:oItem.getBindingContext()。getPath()。substr(oItem.getBindingContext()。getPath()。length-1)//oItem.getBindingContext()。getProperty(" Name")
 });
 }
 });


 返回TableController;


 });
 

Persona.controller.js:

 sap.ui.define([
 " ./BaseController",
 'sap/ui/model/json/JSONModel',
 'sap/m/MessageToast',
 'sap/ui/core/routing/History'
 ],函数(BaseController,JSONModel,MessageToast,历史记录){
 "使用严格";


 var PageController = BaseController.extend(" opensap.myapp.controller.Persona",{




 onInit:function(){
 var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
 oRouter.getRoute(" persona")。attachPatternMatched(this._onObjectMatched,this);
 },

 _onObjectMatched:函数(oEvent){
 this.getView()。bindElement({
 路径:"/img/PersonaCollection/" + oEvent.getParameter(" arguments")。objectId,
         模特:"角色"
 });
 MessageToast.show(oEvent.getParameter(" arguments")。objectId);
 },


 onNavBack:function(){
 var sPreviousHash = History.getInstance()。getPreviousHash();


 如果(sPreviousHash!==未定义){
 history.go(-1);
 }其他{
 this.getRouter()。navTo(" Table",{},true);
 }
 }



 });

 返回PageController;


 });
 

Persona.view.xml:

 


 

 
 <标题
 text =" {Name}"
 level =" H2"/>

 



 

  
  
 




 


 
 

manifest.json:

 {
 " _version":" 1.3.0",
 " sap.app":{
 " _version":" 1.3.0",
 " id":" opensap.myapp",
 " type":"应用程序",
 " title":" {{appTitle}}",
 " description":" {{appDescription}}",
 " applicationVersion":{
 " version":" 1.0.0"
 }
 },
 " sap.ui":{
 " _version":" 1.3.0",
 " technology":" UI5",
 " deviceTypes":{
 "桌面":是的,
 "平板电脑":是的,
 "电话":正确
 },
 " supportedThemes":[
 " sap_bluecrystal"
 ]
 },
 " sap.ui5":{
 " _version":" 1.2.0",
 " rootView":{
 " viewName":" opensap.myapp.view.App",
 " type":" XML",
 " id":" app"
 },
 " autoPrefixId":是,
 "依赖关系":{
 " minUI5Version":" 1.34",
 " libs":{
 " sap.ui.core":{
 " minVersion":" 1.34.0"
 },
 " sap.m":{
 " minVersion":" 1.34.0"
 },
 " sap.ui.layout":{
 " minVersion":" 1.34.0"
 }
 }
 },
 " contentDensities":{
 "紧凑":是的,
 "舒适":是
 },
 "路由":{
 " config":{
 " routerClass":" sap.m.routing.Router",
 " viewType":" XML",
 " viewPath":" opensap.myapp.view",
 " controlId":" app",
 " controlAggregation":"页面",
 "异步":true
 },
 "路线":[
 {
 " pattern":"",
 " name":"表",
 "目标":[
 "表"
 ]
 },
 {
 " pattern":"角色/{objectId}",
 " name":"角色",
 "目标":[
 "角色"
 ]
 }
 ],
 "目标":{
 "表格":{
 " viewName":"表格",
 " viewId":"表格",
 " viewLevel":1
 },
 "角色":{
 " viewName":" Persona",
 " viewId":"角色",
 " viewLevel":2
 }
 }
 }
 }
 }
 

personas.json(前2个元素):

 {
 " PersonaCollection":[
 {
 "名称":" Abaddon",
 " arcana":"判决",
 "级别":74,
 "统计信息":[51、38、58、43、39],
 " elems":[" ab"," ab","-","-","-","-"," wk"," wk","-"," ab"],
 "技能":{
 "吸收物理":79,
 "死神":0,
 " Gigantomachia":80,
 " Makarakarn":0,
 "精神流失":0,
 "生存技巧":77
 }
 },
 {
 "名称":" Agathion",
 " arcana":"战车",
 "级别":3,
 "统计信息":[3,4,5,7,3],
 " elems":["-"," rs","-","-"," rs"," wk","-","-","-","-"]],
 " skills":{" Baisudi":0," Dia":0," Dodge Elec":8," Lunge":4," Rakukaja":6," Zio":0},
 "个性":" Timid"
 },
 。
 。
 。

该视图是一种非常原始的视图,因为我仅使用它来测试路由是否目前有效。

有什么我想念的吗? 感谢您的关注和事先的帮助。

付费偷看设置
发送

一周热门 更多>