【问题标题】:Binding data JSON SAPUI5 (Tiles Menu)绑定数据 JSON SAPUI5(Tiles Menu)
【发布时间】:2017-05-04 04:23:51
【问题描述】:

我想绑定图块菜单,但绑定选择有问题。我有一个 JSON 结构:

{
        "module":{
            "module":[
                {
                    "id": "0",
                    "name": "Kepesertaan"
                },
                {
                    "id": "1",
                    "name": "Layanan dan Manfaat"
                },
                {
                    "id": "2",
                    "name": "Investasi"
                },
                {
                    "id": "3",
                    "name": "Perbendaharaan"
                },
                {
                    "id": "4",
                    "name": "Aktuaria"
                }               
            ],

            "system":[
                {
                    "id": "5",
                    "name": "Pengumuman"
                }
            ]
        }
}

控制器:

    onInit: function(oEvent){
        var oModel = new JSONModel("metroui/module.json");
        this.getView().setModel(oModel);
    },

    pressTileModule : function(oEvent){
        var sPath = oEvent.getSource().getBindingContext().getPath();
        var oModel = this.getView().getModel();
        var oContext = oModel.getProperty(sPath); 
    }

XML:

<core:View  xmlns:core="sap.ui.core" 
            xmlns:mvc="sap.ui.core.mvc" 
            xmlns="sap.m"
            xmlns:l="sap.ui.layout"
            xmlns:tnt="sap.tnt"
            controllerName="metroui.MetroUI" 
            xmlns:html="http://www.w3.org/1999/xhtml">

            <App id="navCon">
                <pages>
                    <Page id="module" showHeader="false">
                        <Panel headerText="Module">
                            <content>
                                <l:HorizontalLayout
                                    id="TileContainerModule"
                                    allowWrapping="true"
                                    content="{/}">
                                        <GenericTile class="sapUiTinyMarginBegin sapUiTinyMarginTop tileLayout" 
                                            header="{name}" press="pressTileModule">
                                            <tileContent>
                                                <TileContent>
                                                    <content>
                                                        <ImageContent description="{id}" src="sap-icon://list"/>
                                                    </content>
                                                </TileContent>
                                            </tileContent>
                                        </GenericTile>
                                </l:HorizontalLayout>
                            </content>  
                        </Panel>    
                    </Page>
                </pages>
            </App>      
</core:View>

对于绑定对象模块>模块(来自 JSON),在 XML 文件中的 content="{/module/module}" 中设置,但我想设置内容路径 JSON 在控制器中,因为我想设置条件绑定,有时我只想绑定模块>模块或绑定模块>系统(来自JSON结构)。加载 JSON 文件时如何绑定选择?如果我将 JSON 结构放在控制器中,我可以创建新的 JSON 模型 this.module.module 或 this.module.system 并在 XML 中设置 content="{/}",但是当我加载文件 JSON 时我无法选择绑定.如何解决这个问题?

谢谢, 鲍比

【问题讨论】:

    标签: javascript json xml sapui5


    【解决方案1】:

    这就是我会做的。

    步骤 1. 在 onInit() 中,使用获取 json 对象 var jsonData = $.getJSON("metroui/module.json");

    步骤 2. 检查 jsonData 是否有 'module' 或 'system' 使用 If ('module' in jsonData.module)

    【讨论】:

      猜你喜欢
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多