kendoui过滤模板

时间:2014-09-27 08:40:59

标签: kendo-ui kendo-mobile

我正在学习KendoUI并且有一个简单的问题,但是早上4点30分......

我正在尝试过滤viewModel中的数据列表并通过模板显示它。过滤后的数据显示正确,但我也得到了所有其他行。

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>

1 个答案:

答案 0 :(得分: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;
    }
});