2014-02-28 57 views
2

根據問題「Filtering source in a Kendo Template」中的回答,我使用的是visible binding。根據問題「Javascript inside Kendo Template is giving incorrect result」的答案,我避免了雙重約束。但visible綁定不是它的功能。爲什麼它沒有做到過濾?Kendo UI可見綁定不起作用

Fiddle

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 data-bind="visible: IsSelected"> 
      <tr> 
       <td>#= name #</td> 
       <td>#= age #</td> 
      </tr> 
     </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 } 
         ], 

//   isVisibleCheck: function (e) { 
//    isValid = false; 
//    //person object is created using "e" 
//    var person = e.data; 
//    if (person.age >= 29) { 
//     isValid = true; 
//    } 
//    return isValid; 
//   } 
     }); 

    </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. Visible binding in Kendo UI MVVM- docs.telerik
  2. Filtering source in a Kendo Template
  3. Javascript inside Kendo Template is giving incorrect result

回答

3

一聲,我從你rowTemplate拿出額外<tr></tr>,這似乎很好地工作。

<tr data-bind="visible: IsSelected"> 
    <td>#= name #</td> 
    <td>#= age #</td> 
</tr> 

看樣...... http://jsbin.com/vusav/1/edit

+0

Thanks..But我很奇怪,爲什麼是劍道給出不正確的結果,而不是拋出錯誤。這可能會導致很難找到的微妙的錯誤。如果這是一個更加親切的錯誤。 – Lijo

+1

劍道走了沒有錯,所以沒有什麼可扔的。看看輸出的html。

​​Lijo​​28
沒有什麼錯誤的,只是一些奇怪的HTML被輸出。注意帶有可見綁定的tr,不包含兩個數據綁定td。 –