过滤剑道模板中的来源

时间:2014-02-27 14:57:14

标签: javascript jquery html5 mvvm kendo-ui

我有以下Kendo模板和MVVM绑定。这个模板的源代码是viewModel,里面有employees。员工集合中有3条记录。我只需要显示IsSelected属性为true的记录。

<!----Kendo Templates-->
<script id="row-template" type="text/x-kendo-template">
      <tr>
            <td data-bind="text: name"></td>
            <td data-bind="text: age"></td>
      </tr>
</script>


employees: [
                    { name: "Lijo", age: "28", IsSelected: true },
                    { name: "Binu", age: "33", IsSelected: false },
                    { name: "Kiran", age: "29", IsSelected: false }
                   ]

问题

我们如何在模板中指定此过滤?

CODE

<head>
    <title>Template Filtering</title>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
    <!----Kendo Templates-->
    <script id="row-template" type="text/x-kendo-template">
          <tr>
                <td data-bind="text: name"></td>
                <td data-bind="text: age"></td>
          </tr>
    </script>
    <!--MVVM Wiring using Kendo Binding-->
    <script type="text/javascript">

        $(document).ready(function () {
            kendo.bind($("body"), viewModel);
        });

    </script>
    <script type="text/javascript">
        var viewModel = kendo.observable({

            employees: [
                        { name: "Lijo", age: "28", IsSelected: true },
                        { name: "Binu", age: "33", IsSelected: false },
                        { name: "Kiran", age: "29", IsSelected: true }
                       ]
        });

    </script>

    <style>
        table, th, td
        {
            border: 1px solid black;
        }
    </style>

</head>
<body>
    <table id="resultTable">
        <tbody data-template="row-template" data-bind="source: employees">
        </tbody>
    </table>
</body>

参考

  1. KendoUI Check Boxes in a Grid: how to and some tips and tricks
  2. Filter kendo ui grid with filed type object
  3. Filter Array|Object
  4. MVVM / Source and template binding
  5. how to run a function inside a template

1 个答案:

答案 0 :(得分:1)

使用可见绑定...

使用可见绑定

<script id="row-template" type="text/x-kendo-template">
    <tr data-bind="visible: IsSelected">
        <td data-bind="text: name"></td>
        <td data-bind="text: age"></td>
    </tr>
</script>