xiaolizi007
11/22/2016 - 6:53 AM

From http://wiki.jikexueyuan.com/project/kendo-ui-development-tutorial/kendo-mvvm-source.html 当 ViewModel 的值 为一数组时,那么通过 Source 绑定到模板时,会把数组中每

From http://wiki.jikexueyuan.com/project/kendo-ui-development-tutorial/kendo-mvvm-source.html 当 ViewModel 的值 为一数组时,那么通过 Source 绑定到模板时,会把数组中每个元素逐个应用到模板,最后的输出为应用这些模板的结果的综合。 添加删除数组中的内容,显示的内容也随之变化


<ul data-template="ul-template" data-bind="source: products">
</ul>
<script id="ul-template" type="text/x-kendo-template">
    <li>
        id: <span data-bind="text: id"></span>
        name: <span data-bind="text: name"></span>
    </li>
</script>
<script>
var viewModel = kendo.observable({
    products: [
        { id: 1, name: "Coffee" },
        { id: 2, name: "Tea" },
        { id: 3, name: "Juice" }
    ]
});

kendo.bind($("ul"), viewModel);
</script>