2016-12-27 109 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"> 
相关问题