【问题标题】:kendoui filtering templatekendoui 过滤模板
【发布时间】:2014-09-27 08:40:59
【问题描述】:

我正在学习 KendoUI,并且有一个可能很简单的问题,但现在是凌晨 4:30...

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

<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>

【问题讨论】:

    标签: kendo-ui kendo-mobile


    【解决方案1】:

    改变了我的方法,因为我不喜欢模板中的逻辑:

    <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;
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2012-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-29
      • 2014-10-24
      • 1970-01-01
      • 2023-03-29
      相关资源
      最近更新 更多