2017-09-01 81 views
1

我有一個自定義控件,它在「詳細視圖」頁面中插入了多個屬性。我用這些屬性綁定了數據。情景是我有兩個頁面,一個是列表視圖,然後是詳細視圖。我需要從詳細信息頁導航並從主頁選擇差異產品。詳細查看頁面根據選定的產品顯示差異產品詳細信息。一切正常。但問題是我的自定義控件不更新值,其他頁面有更新的值。更新模型時刷新sapui5中的自定義控件

<custom:product topic="" subTopic="{product>name}" id="productDetial"></custom:product> 

我用一個methond this.getView().byId("productDetail").rerender();但它不更新控制我內心的HTML。

控制碼。可能是一些拼寫錯誤。因爲我更改了一些變量名稱並刪除了不需要的代碼。目的是爲了表明我已經使用的方法,我怎麼沒

sap.ui.define([ 
     "sap/m/Label", 
     "sap/m/Button", 
     "sap/m/CustomTile" 

    ], function(Label, Button, CustomTile) { 
     "use strict"; 
     jQuery.sap.declare("testProduct.control.product"); 
     return CustomTile.extend("testProduct.control.product", { 
       metadata: { // the Control API 
        properties: { 
         name: { 
          type: "string", 
          defaultValue: "--" 
         }, 
         subTopic: { 
          type: "string", 
          defaultValue: "--" 
         } 
        } 

       }, 
       init: function() { 

       }, 

       rerender: function(oRM, oControl) { 

       }, 
       renderer: function(oRM, oControl) { 
        oRM.write('<div class=" sapMTile customTileCourseDetail">'); 
        oRM.write('<div class="leftTileYourScore">'); 
        if (oControl.getSubTopic() !== "" && oControl.getSubTopic() !== undefined) { 
         oRM.write(oControl.getSubTopic()); 
        } else { 
         oRM.write("&nbsp;"); 
        } 
        oRM.write('</div>'); 
        oRM.write('</div> 
        } 
       }); 
     }); 
+0

您將有機會分享特定的自定義控制更多的代碼,找出問題 –

+0

你有沒有嘗試刷新模式,而不是控制,比如'this.getView()。getModel()。刷新(TURE );'?參數'true'強制刷新使用正在刷新的模型的控件。 – keshet

+0

是的,我試過了。即使當我使用控制檯數據它給了我更新的記錄。但在頁面上顯示仍然是前一個 – afaq

回答

1

呦只需要在你的控制添加setter函數。當綁定刷新/更改時,UI5將觸發特定於該屬性的setter方法。所以在你的情況下屬性subTopic它期望一個方法setSubTopic。這個方法應該定義你自己的邏輯來根據你的需要更新UI層的屬性。

這是您需要添加的代碼的一部分,您還必須稍微調整初始渲染邏輯。

renderer: function (oRM, oControl) { 
     //oRM.write('<div class=" sapMTile customTileCourseDetail">'); 
     oRM.write("<div") 
     oRM.writeControlData(oControl); 
     oRM.addClass("sapMTile customTileCourseDetail"); 
     oRM.writeClasses(); 
     oRM.write(">"); 
     oRM.write('<div class="leftTileYourScore">'); 
     if (oControl.getSubTopic() !== "" && oControl.getSubTopic() !== undefined) { 
      oRM.write(oControl.getSubTopic()); 
     } else { 
      oRM.write("&nbsp;"); 
     } 
     oRM.write('</div>'); 
     oRM.write('</div>'); 
    }, 

    setSubTopic: function(sText){ 
     this.setProperty("subTopic", sText, true); 
     $("#"+this.sId+" .leftTileYourScore").html(sText); 
    }