如何按需切换视图 [英] How to switch views on demand

查看:54
本文介绍了如何按需切换视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<semantic:DetailPage title="Detail Page Title">
  <mvc:XMLView viewName="query.sap.view.Table" />
  <mvc:XMLView viewName="query.sap.view.chart" />
</semantic:DetailPage>

我在同一内容中有两个嵌套视图,我只想显示其中一个.当我按下一个按钮时,它应该切换到另一个.

I have two nested views in the same content and I want to display only one of them. When I press a button, it should switch to the other one.

推荐答案

让我们有一个开关并将其当前值保存到本地 JSON 模型.现在,我们将使用此值在 2 个视图之间切换.如果开关为真,则显示第一个视图,否则显示第二个开关.

Lets have a switch and save its current value to a local JSON Model. Now, we will use this value to switch between the 2 views. If switch is true, show first view else show second switch.

代码如下:

XML(我只是用文本代替了视图(同样的事情)):

XML ( I've just used the texts in place of View (same thing)) :

        <Switch state='{/showFirstView}' />
        <Text text='TExt 1' visible='{/showFirstView}' />
        <Text text='TExt 2' visible='{=!${/showFirstView}}' />

控制器:

onInit: function() {
        var model = new sap.ui.model.json.JSONModel({showFirstView:true});
        this.getView().setModel(model);
    },

它有效.截图:

和:

这篇关于如何按需切换视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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