2016-12-27 106 views
-2

我正在用SAPUI5構建應用程序。檢測我的應用程序是否在電話上運行

在這個應用程序,我有一個XML觀點如下:

<Dialog id="confirmDialog" 
     title="Confirm" 
     showHeader="true" 
     state="Warning" 
     stretch="true" 
     type="Standard"> 

我想要的屬性stretch設置爲true只有當我發現,如果我的應用程序在手機上運行。

我該如何實現它?

回答

0

您可以創建設備模型並使用其屬性來了解應用程序是否在手機上運行。請參閱以下鏈接:
https://help.sap.com/saphelp_uiaddon10/helpdata/en/32/5b8edafcfa4c9c8fbd42455a60e379/content.htm

編輯:

方法1:如果您的設備模型成立,那麼你就可以在你的代碼中使用它: 在Component.js:

var deviceModel = new sap.ui.model.json.JSONModel({ 
      isTouch : sap.ui.Device.support.touch, 
      isNoTouch : !sap.ui.Device.support.touch, 
      isPhone : sap.ui.Device.system.phone, 
      isNoPhone : !sap.ui.Device.system.phone, 
      listMode : sap.ui.Device.system.phone ? "None" : "SingleSelectMaster", 
      listItemType : sap.ui.Device.system.phone ? "Active" : "Inactive" 
     }); 
     deviceModel.setDefaultBindingMode("OneWay"); 
     this.setModel(deviceModel, "device"); 
如果喲 sap.ui.Device.system.phone值:

在XML:

<Dialog id="confirmDialog" 
     title="Confirm" 
     showHeader="true" 
     state="Warning" 
     stretch="{device>/isPhone}" 
     type="Standard"> 

方式二:您可以隨時使用你不想創建一個單獨的模型。但是,我建議您創建一個設備模型並使用它。

<Dialog id="confirmDialog" 
      title="Confirm" 
      showHeader="true" 
      state="Warning" 
      stretch="sap.ui.Device.system.phone" 
      type="Standard"> 
相關問題