刷新绑定数据后,kendo ui网格失败

时间:2013-01-07 10:17:21

标签: kendo-ui kendo-grid knockout-2.0

我正在使用knockout-kendo,这是我的代码: 标记:

<body>
<div id="mursi"
     data-bind="kendoGrid:{ dataSource:{data:selectedAsset().RealEstateAssetBlockParcel ,pageSize:3} ,data:selectedAsset().RealEstateAssetBlockParcel, pageable: true,pageSize:5,sortable:true,scrollable:false,selectable:true,columns:[{title:'parcel'},{title:'plot'},{title:'subplot'},{ width:60},{ width:60}] ,rowTemplate: 'rowParcelTmpl', altRowTemplate: 'altParcelTmpl', useKOTemplates: true }"></div>

<button data-bind="replaceSelectedAsset">click me</button>

<script id="rowParcelTmpl" type="text/html">
    <tr>
        <td>
            <div data-bind="text:Block"></div>
        </td>
        <td>
            <div data-bind="text:Plot"></div>
        </td>
        <td>
            <div data-bind="text:SubPlot"></div>
        </td>
        <td>
            <button class="k-button"><span class="update-button"></span></button>
        </td>
        <td>
            <button class="k-button"><span class="remove-button"></span></button>
        </td>
    </tr>
</script>
<script id="altParcelTmpl" type="text/html">
    <tr class="k-alt">
        <td>
            <div data-bind="text:Block"></div>
        </td>
        <td>
            <div data-bind="text:Plot"></div>
        </td>
        <td>
            <div data-bind="text:SubPlot"></div>
        </td>
        <td>
            <button class="k-button"><span class="update-button"></span></button>
        </td>
        ><span class="remove-button"></span></button></td>
    </tr>
</script>
</body>

这是我的JS:

var selectedAsset = ko.observable();
//viewmodels
var assetViewModel = function () {
    this.RealEstateAssetBlockParcel = ko.observableArray([]);
};
var asset = new assetViewModel();
asset.RealEstateAssetBlockParcel.push({Block: 1, Plot: 2, SubPlot: 3, Id: 0});
selectedAsset(asset);
var replaceSelectedAsset = function () {
    selectedAsset(asset);
};
ko.applyBindings();

一切顺利,直到你按下“点击我”按钮,该按钮假设选择另一个资产并显示其宗地网格, 相反,我得到以下错误:“未捕获TypeError:无法调用方法'找到'未定义” (起源于kendo.web.all)

http://jsbin.com/oboxig/3/edit 帮助将不胜感激 感谢

1 个答案:

答案 0 :(得分:1)

我在你看到的内容JSBin是data-bind的{​​{1}}中的错误。

你可以尝试一下:

button

并将function replaceSelectedAsset () { selectedAsset(asset); }; 定义为:

button