在sapui5中将数据从一个XML View Controller获取到另一个View Controller时出现问题 [英] Issue while getting data from one XML View Controller to Another view controller in sapui5

查看:198
本文介绍了在sapui5中将数据从一个XML View Controller获取到另一个View Controller时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将一种xml视图控制器方法用于另一种XML视图控制器.这是一个示例(仅控制器文件):

I have to use the one xml view controller methods into another XML View controller. Here is an example (controller files only):

**view1.js**
sap.ui.controller("sap.ui.xml.view.View1", {
  onInit: function() {
    this.globalCount = 0;
    loadedView1 = this.getView(); //loadedViews is a global variable which is defined in component.js
  },
  increaseCount: function(){
   this.globalCount++;
  }
});

**view1.xml**
<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
    xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:c="sap.ui.commons" xmlns:f="sap.ui.layout.form"
    controllerName="sap.ui.fisa.view.OrderDetails" xmlns:html="http://www.w3.org/1999/xhtml">
    <Page showNavButton="true"  >
     <content>
        <Label text="example text" />
     </content>
    </Page>

第二个视图:

**view2.js**
    sap.ui.controller("sap.ui.xml.view.View2", {
      onInit: function() {

         this.view2Count = loadedView1.getController().globalCount ;

      }
    });

    **view2.xml**
    <core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
        xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:c="sap.ui.commons" xmlns:f="sap.ui.layout.form"
        controllerName="sap.ui.xml.view.View2" xmlns:html="http://www.w3.org/1999/xhtml">
        <Page showNavButton="true"  >
         <content>
            <Label text="Second View" />
         </content>
        </Page>
</core:View>

我能够从加载的视图中获取数据,但是当我尝试重新加载view2时,loadedView1.getController()的值为 null .

I am able to get the data from the loaded view, but when I try to reload the view2 the value of loadedView1.getController() is null.

推荐答案

在组件中实例化一个全局JSONModel并将视图计数存储在该组件中.可以通过调用组件的 onInit 方法中的 setModel 使该模型在全球范围内可用.

Instantiate a global JSONModel in your component and store the view count there. The model can be made globally available by calling setModel in the component's onInit method.

这篇关于在sapui5中将数据从一个XML View Controller获取到另一个View Controller时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆