2017-04-21 82 views
0

一個不正確的請求我有一個XML文件這樣避免從視圖

view.xml用列表

<List 
    id="myList" 
    items="{ 
     path: '/myEntitySet' 
    }"> 
    <items> 
     <StandardListItem 
      title="{myTitle}" /> 
    </items> 
</List> 

「myEntitySet」需要一個動態濾波器參數(MYID),用於運作響應否則我會從後端收到404錯誤。 所以我使用JavaScript來將一個過濾器添加到我的列表中。

controller.js

var oBinding = this.getView().byId("myList").getBinding("items"); 
var aFilter = [ new sap.ui.model.Filter("myId", sap.ui.model.FilterOperator.EQ, myDynamicId) ]; 

oBinding.filter({      
      filters: aFilter 
      }); 

問題: 的 「控制器請求」,並且請求之前的 「查看請求」 火災毫秒失敗(404錯誤)。 我不想通過JS渲染列表以避免來自視圖的請求。有沒有辦法阻止查看請求?

回答

3

有幾個方法可以做到這一點。

最簡單的是直接做過濾中的XML,但我相信自己的動態過濾參數不能在設計時寫的,所以這個選項了。

您只能在控制器中進行綁定。因爲你說過你不想用JavaScript渲染列表,所以你可以使用下面的代碼片斷。

查看:

<List id="myList"> 
    <dependents> 
     <StandardListItem id="myItem" title="{myTitle}" /> 
    </dependents> 
</List> 

控制器:

this.byId("myList").bindItems("/myEntitySet", { 
    template: this.byId("myItem"), 
    //optional: 
    templateShareable: true 
}); 

另一種可能性是使用OData的模型(V2)的遞延批組功能。基本上,您可以通過給批量請求groupId將請求分組在一個批處理請求中。

如果您將此組標記爲延遲組,則在調用OData模型的submitChanges方法時提交組(及其包含的請求)。查看ODataListBindingODataModel的文檔。

查看:

<List id="myList" items="{ 
    path: '/myEntitySet', 
    parameters: {batchGroupId: 'myGroup'} 
}"> 
    <StandardListItem title="{myTitle}" /> 
</List> 

控制器:

//in onInit 
this.getModel().getDeferredGroups(["myGroup"]); 

//after you added the filter 
this.getModel().submitChanges(); 
+0

「錯誤:元素的聚集物品缺少模板或工廠函數...「爲 」家屬「 - 溶液 '<列表ID =」 MasterList 「模式= 」無「 選擇= 」onListItemPressed「 \t \t \t \t> \t \t \t \t \t \t \t \t \t ' – alexP

+0

誤差不來回回(假設那就是你在那裏寫的全部內容),但是來自你約束列表的地方。確保你正在傳遞'template'(錯誤表示你沒有傳遞模板)。 –

+0

在 「onAfterRendering」 我打電話 'oList.bindItems( 「/ myEntitySet」,{ \t \t \t \t \t \t模板:self.byId( 「MasterListItem」), \t \t \t \t \t \t濾波器:[新的SAP。 ui.model.Filter({ \t \t和:真, \t \t過濾器:aFilter \t \t},假)], \t \t \t \t \t \t //可選: \t \t \t \t \t \t templateShareable:真 \t \t \t \t \t \t});' 我得到'self.byId( 「MasterListItem」 模板)' BTW :[ListBase](https://sapui5.hana.ondemand.com/explored.html#/entity/sap.m.ListBase/aggregations)中沒有像依賴關係那樣的聚合關於這方面的更多信息? – alexP