2017-04-25 1 views
3

안녕을 제거하지 않고 두 번째 필터를 추가합니다. 이런 식으로 :난 뒤에이 코드와 searchfield을 가지고있는 기존에게

onSetFilter : function(oEvent) { 
    var andFilter = []; 
    andFilter.push(new Filter("BusArea", FilterOperator.EQ, "5000")); 
    this._applySearch(andFilter); 
}, 

물론 "BusArea"부분은 어떤 필터가 선택되었는지에 따라 달라집니다. 하나 이상의 필터가 될 수 있습니다. _applySearch 함수는 다음과 같다 :

_applySearch: function(andFilter) { 
    var oViewModel = this.getModel("worklistView"); 
    this._oTable.getBinding("items").filter(andFilter, true); 
    // changes the noDataText of the list in case there are no filter results 
    if (andFilter.length !== 0) { 
     oViewModel.setProperty("/tableNoDataText", 
     this.getResourceBundle().getText("worklistNoDataWithSearchText")); 
    } 
} 

문제 나 필터 버튼을 통해 필터를 추가 할 때, 검색 창에서 필터가 사라지고 arround를 다른 방법이다. 기존 코드를 제거하지 않고 필터를 추가 할 수 있도록 코드를 어떻게 바꿀 수 있습니까?

+0

를 제출 중 때 우리는 유지하여 여러 개의 필터를 적용() 함수를 입력은 SearchField

모두 글로벌 "filtersModel"에 대해 바인더 제본되어 시뮬레이션, 모두는 _calculateFilters 전화 제어기 레벨의 필터 배열. 그래서 우리는 먼저 this.aFilters.push (oFilter)와 같은 배열로 필터를 푸시 한 다음 this.aFilters를 바인딩에 적용합니다. 더 나은 솔루션을 찾고 있습니다. –

답변

1

하나의 해결책은 바인딩 정보에서 필터를 가져와 and을 사용하여 새 필터와 함께 다시 푸시하는 것입니다.

+0

좋아, 나는 그런 식으로 필터가 쌓일 것이다. 그 문제를 해결하는 방법에 대한 생각이 있습니까? – freshrebel

+0

@freshrebel 지금 당신의 요지를 봅니다. 나는 당신이 원하는 것을 오해 할 수도 있습니다. 검색 버튼을 누를 때마다 모든 필터 컨트롤을 반복하고 값으로 필터를 다시 작성할 가능성이 있습니까? – Allen

+0

괜찮 았으나 내 필터 (searchfiel이 아니므로)는 https://sapui5.hana.ondemand.com/explored.html#/sample/sap.m.sample.ViewSettingsDialog/preview와 같은 대화 상자에서 표시됩니다. 닫힌 후에도 대화 상자에서 값을 가져올 수 있습니까? – freshrebel

1

채팅으로 대화를 한 후, 글로벌 모델을 사용하여이 스 니펫을 만들었습니다.

https://jsbin.com/pewavuhonu/edit?html,output

콤보 상자와 버튼은 대화를 시뮬레이션합니다. [정보]

<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t \t <meta http-equiv='X-UA-Compatible' content='IE=edge'> 
 
\t \t <meta charset="utf-8"> 
 

 
\t \t <title>MVC with XmlView</title> 
 

 
\t \t <!-- Load UI5, select "blue crystal" theme and the "sap.m" control library --> 
 
\t \t <script id='sap-ui-bootstrap' 
 
\t \t \t src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js' 
 
\t \t \t data-sap-ui-theme='sap_bluecrystal' 
 
\t \t \t data-sap-ui-libs='sap.m' 
 
\t \t \t data-sap-ui-xx-bindingSyntax='complex'></script> 
 

 

 
\t \t <!-- DEFINE RE-USE COMPONENTS - NORMALLY DONE IN SEPARATE FILES --> 
 

 
\t \t <!-- define a new (simple) View type as an XmlView 
 
\t \t - using data binding for the Button text 
 
\t \t - binding a controller method to the Button's "press" event 
 
\t \t - also mixing in some plain HTML 
 
\t \t note: typically this would be a standalone file --> 
 

 
\t \t <script id="view1" type="sapui5/xmlview"> 
 
\t \t <mvc:View xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" controllerName="my.own.controller"> 
 
\t \t \t <Panel headerText="Filters"> 
 
\t \t \t \t <VBox> 
 
\t \t \t \t \t <HBox> 
 
\t \t \t \t \t \t <Label text="Filter by Customer:" class="sapUiSmallMarginTop sapUiSmallMarginEnd"/> 
 
\t \t \t \t \t \t <ComboBox id="comboBox" selectedKey="{filtersModel>/customerFilter}"> 
 
\t \t \t \t \t \t \t <items> 
 
\t \t \t \t \t \t \t \t <core:Item key="VINET" text="VINET" /> 
 
\t \t \t \t \t \t \t \t <core:Item key="TOMSP" text="TOMSP" /> 
 
\t \t \t \t \t \t \t \t <core:Item key="HANAR" text="HANAR" /> 
 
\t \t \t \t \t \t \t \t <core:Item key="VICTE" text="VICTE" /> 
 
\t \t \t \t \t \t \t \t <core:Item key="SUPRD" text="SUPRD" /> 
 
\t \t \t \t \t \t \t </items> 
 
\t \t \t \t \t \t </ComboBox> 
 
\t \t \t \t \t \t <Button text="Apply this Filter" press="_calculateFilters"></Button> 
 
\t \t \t \t \t </HBox> 
 
\t \t \t \t </VBox> 
 
\t \t \t \t <VBox> 
 
\t \t \t \t \t <HBox> 
 
\t \t \t \t \t \t <Input value="{filtersModel>/shipAddressFilter}" id="input" submit="_calculateFilters" width="500px" placeholder="Filter by ShipAddress: Write and enter for filtering"/> 
 
\t \t \t \t \t </HBox> 
 
\t \t \t \t </VBox> 
 
\t \t \t </Panel> 
 
\t \t \t <Panel> 
 
\t \t \t \t <List id="list" items="{/Orders}"> 
 
\t \t \t \t \t <StandardListItem title="{CustomerID}" info="{ShipAddress}"/> 
 
\t \t \t \t </List> 
 
\t \t \t </Panel> 
 
\t \t </mvc:View> 
 
     </script> 
 

 

 
\t \t <script> 
 
\t \t \t // define a new (simple) Controller type 
 
\t \t \t sap.ui.controller("my.own.controller", { 
 
\t \t \t \t 
 
\t \t \t \t onInit: function(){ 
 
\t \t \t \t \t var oFiltersModel = new sap.ui.model.json.JSONModel(); 
 
\t \t \t \t \t sap.ui.getCore().setModel(oFiltersModel, "filtersModel"); 
 
\t \t \t \t }, 
 
\t \t \t \t 
 
\t \t \t \t _calculateFilters: function(){ \t \t \t \t \t 
 
\t \t \t \t \t var \t oSelect = this.getView().byId("comboBox"), 
 
\t \t \t \t \t \t oListBinding = this.getView().byId("list").getBinding("items"), 
 
\t \t \t \t \t \t oFiltersModel = sap.ui.getCore().getModel("filtersModel"), 
 
\t \t \t \t \t \t oCustomerFilterValue = oFiltersModel.getProperty("/customerFilter"), 
 
\t \t \t \t \t \t oShipAddressValue = oFiltersModel.getProperty("/shipAddressFilter"), 
 
\t \t \t \t \t \t oFilters = []; 
 
\t \t \t \t \t 
 
\t \t \t \t \t if(oCustomerFilterValue){ 
 
\t \t \t \t \t \t oFilters.push(new sap.ui.model.Filter("CustomerID", "EQ", oCustomerFilterValue)); 
 
\t \t \t \t \t } 
 
\t \t \t \t \t if(oShipAddressValue){ 
 
\t \t \t \t \t \t oFilters.push(new sap.ui.model.Filter("ShipAddress", "Contains", oShipAddressValue)); 
 
\t \t \t \t \t } 
 
\t \t \t \t \t 
 
\t \t \t \t \t oListBinding.filter(oFilters); 
 
\t \t \t \t } 
 
\t \t \t }); 
 
\t 
 
\t 
 
\t 
 
\t \t \t /*** THIS IS THE "APPLICATION" CODE ***/ 
 

 
\t \t \t // create some dummy JSON data 
 
\t \t \t var data = { 
 
\t \t \t \t actionName: "Say Hello" 
 
\t \t \t }; 
 

 
\t \t \t // instantiate the View 
 
\t \t \t var myView = sap.ui.xmlview({viewContent:jQuery('#view1').html()}); // accessing the HTML inside the script tag above 
 

 
\t \t \t // create a Model and assign it to the View 
 
\t \t \t var uri = "https://cors-anywhere.herokuapp.com/services.odata.org/Northwind/Northwind.svc"; // local proxy for cross-domain access 
 
\t \t \t var oModel = new sap.ui.model.odata.ODataModel(uri, { 
 
\t \t \t \t maxDataServiceVersion: "2.0" 
 
\t \t \t }); 
 
\t \t \t myView.setModel(oModel); 
 
    \t  \t 
 

 
\t \t \t // put the View onto the screen 
 
\t \t \t myView.placeAt('content'); 
 

 
\t \t </script> 
 
\t 
 
\t </head> 
 
\t <body id='content' class='sapUiBody'> 
 
\t </body> 
 
</html>

+0

고맙습니다. 그러나 이렇게하면 필터를 변경하거나 새로운 검색을 수행 할 때마다 필터가 스택됩니다. 그걸 해결하는 방법에 대한 어떤 생각? – freshrebel

+0

Filter 개체에 ID 및 ID를 지정하면 현재 필터 배열에서 식별 할 수 있습니다. 그런 다음 새 필터를 추가 할 때마다 새 필터와 동일한 ID를 가진 새 필터가 있는지 확인하십시오. 그렇다면 그것을 튀기고 새 것을 밀어 넣으십시오. 이 링크의 –

+0

: https : //openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.Filter.html 필터에 ID를 부여하는 매개 변수가 없습니다. 그래서 내가 어떻게 할 수 있니? – freshrebel