Kendo knockout:重新绑定列模板

Kendo knockout: re-bind column template

我正在使用 kendo-knockout 库。我创建了一个动态 table 以便我可以切换数据源。我进行了自定义绑定,在更新事件期间我销毁了网格,然后设置了新选项(数据源、列、架构等)和 "recreate" 网格。但是我无法重新绑定我在列中设置的模板。

  var grid = $(element).data('kendoGrid');
  grid.thead.remove();
  grid.destroy();

--- 新选项

column.template = "<a data-bind=\"text: status,  css: {'errorMessage': true}, click: $root.openPopup \">${status}</a>";


                $scope.dataSource({
                    data: items,
                    columns: columns,
                    schemaModelFields: schema
                });

更新期间在活页夹中

 function (dataSource, element, vm) {
    [...]
     var gridOptions = {
                    columns: columns,
                    dataSource: {
                        data: data,
                        schema: {
                            model: {
                                fields: schemaModelFields
                            }
                        }
                    }, 
                    [...] 



 $(element).kendoGrid(gridOptions);

我希望能够从根 VM 调用 openPopup 方法。它确实正确地呈现了模板,但绑定被破坏了。

<a data-bind="text: status,  css: {'errorMessage': true}, click: $root.openPopup">Not Set</a>

我得到了答案...使用 dataBound 事件我清理节点并重新应用绑定

        var gridOptions = {
                columns: columns,
                dataSource: {
                    type: 'knockout',
                    data: data,
                    schema: {
                        model: {
                            fields: schemaModelFields
                        }
                    }
                },
                useKOTemplates: true,
                dataBound: dataBound,
                preventBinding: true,                    
            };

            var grid = $(element).kendoGrid(gridOptions);

           var dataBound = function () {
            var body = this.element.find("tbody")[0];

            if (body) {
                ko.cleanNode(body);
                ko.applyBindings(ko.dataFor(body), body);
            }
        }

这解决了我的问题,但适用于投标的上下文是来自根的 VM,而不是数据源项目,因此在 $root.openPopup 中,我得到的参数是完整的 VM 而不是行项目。