2014-09-27 110 views
0

我學習KendoUI又有什麼可能是一個簡單的問題,但在早上是它4:30 ...kendoui過濾模板

我試圖篩選數據的列表視圖模型我和現在它通過模板。過濾的數據顯示出來,但正確,但我也得到所有其他行。

enter image description here

<div id="openings" data-role="view" data-model="viewModel.positions" data-show="onShow"> 
<div data-role="header" class="km-header"> 
    <div data-role="navbar" style="background-color: #264e8c; height: 47px;" class="km-widget km-navbar"> 
     <div class="km-leftitem"><a data-role="button" href="views/states.html" data-rel="view" data-align="left" style="background-color: #e5dfc5" class="km-widget km-button"><span class="km-icon km-button-back km-notext"></span></a></div> 
     <span data-role="view-title" style="color: #e5dfc5;">Positions</span> 
     <div class="km-rightitem"><a data-role="button" href="#appDrawer" data-rel="drawer" data-align="right" data-icon="drawer-button" style="background-color: #e5dfc5"></a></div> 
    </div> 
</div> 
<ul id="positionList" data-role="listview" data-bind="source: positions" data-style="inset" data-template="positions-listview-template"></ul> 

和模板

<script id="positions-listview-template" type="text/x-kendo-template"> 
     #if (openingId == viewModel.search.opening.openingId) {# 
     <a href='views/states.html?id=#:id#&name=#:name#' data-id="#:id#" data-role="listview-link" class="j-listview-item"> 
      <div class="j-listview-item-content"> 
       <span>#:name#</span> 
      </div> 
     </a> 
     #}# 
</script> 

回答

0

改變了我的方法,因爲我不喜歡在模板中的邏輯反正:

<ul id="positionList" data-role="listview" data-bind="source: getFilteredList" data-style="inset" data-template="positions-listview-template"></ul> 



positionListViewModel = kendo.observable({ 
    positions: [], 
    load: function (positions) { 
     var that = this; 
     that.set("positions", positions); 
    }, 

    setValues: function (id, name) { 
     var that = this; 
     that.set("id", id); 
     that.set("name", name); 
    }, 

    getFilteredList: function() { 
     var that = this; 
     var filteredList = []; 
     var openingId = viewModel.search.opening.id; 
     var stateId = viewModel.search.state.id; 
     for (var i = 0; i < that.positions.length; i++) { 
      if (that.positions[i].openingId == openingId && (that.positions[i].stateId == stateId || stateId =="All")) { 
       filteredList.push(that.positions[i]); 
      } 
     } 
     return filteredList; 
    } 
});