2015-08-22 43 views
0

我正在使用kendo核心ui(免费版),我不确定我需要在我的视图中做什么来遍历数据...老实说,我我不确定甚至要寻找什么。我尝试使用模板,但无法让它工作。我想在表格中显示数据。这是我的视图模型。如何遍历视图中的kendo datasoure

var dataSource = new kendo.data.DataSource({ 
     transport: { 
      read: { 
       url: '/Customer/GetCustomers', 
       dataType: 'json' 
      } 
     } 
    }); 
    dataSource.read(); 
    var viewModel = kendo.observable({ 
     title: 'Current Customers', 
     AllCustomers: dataSource, 

    }); 

回答

0

原来我让事情变得比他们需要的更困难。我试图在我的模板中应用'for'循环,但它不是必需的。

现在可以正常工作。

HTML

<table data-bind="source: AllCustomers" data-template="template"></table> 
<script id="template" type="text/x-kendo-template"> 
    <tr> 
     <td>#: CompanyName #</td> 
    </tr> 
</script> 

JS

$.ajax("/Customer/GetCustomers", { 

    type: "POST", 
    dataType: "json", 
    success: function (result) { 
     viewModel.set("AllCustomers", result); 
    } 
}); 

var viewModel = kendo.observable({ 
    title: 'Current Customers', 
    AllCustomers: null 
});