与Kendo数据源一起使用基因剔除视图模型

与Kendo数据源一起使用基因剔除视图模型

本文介绍了Kendo-Knockout:与Kendo数据源一起使用基因剔除视图模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Kendo,Knockout和kendo-knockoutjs库进行一些实验.我想将剔除视图模型与kendo数据源一起使用,并将其绑定到kendo网格小部件.

I am doing some experiments with Kendo, Knockout and kendo-knockoutjs libraries. I want to use knockout view model with kendo datasource and to bind it to the kendo grid widget.

在剑道:

html:

<div id="main">
    <div id="reportGrid" data-bind="source: gridDataSource"></div>
</div>

javascript:

javascript:

var billingReportViewModel = kendo.observable({
    gridDataSource: new kendo.data.DataSource({data:[{name:"Apple", color:"green"},{name:"Banana", color:"yellow"}]})
});

$("#reportGrid").kendoGrid();

kendo.bind($("#main"), billingReportViewModel);

http://jsfiddle.net/zeQMT/71/

我想完成的事情:

html与上面的示例相同.

The html is the same as the example above.

javascript:

javascript:

var billingReportViewModel = ko.observable({
    gridDataSource: new kendo.data.DataSource({data:[{name:"Apple", color:"green"},{name:"Banana", color:"yellow"}]})
});

$("#reportGrid").kendoGrid();


ko.applyBindings(billingReportViewModel);

http://jsfiddle.net/zeQMT/72/

过时,这将不起作用,因为基因敲除js没有source绑定.是否可以创建名为source的自定义绑定,以便当前示例正常工作?任何有关工作代码的帮助将不胜感激.谢谢!

Obviuosly, this will not work because knockoutjs does not have source binding. Is it possible to create custom binding named source so that the current example will work? Any help with working code will be greatly appreciated. Thanks!

推荐答案

我很早以前就启动了一个分支来处理直接传递kendo.data.DataSource引用的问题,但从未完成修复: https://github.com/rniemeyer/knockout-kendo/issues/6

I started a branch quite a while ago to handle passing in a kendo.data.DataSource reference directly, but never completed the fix: https://github.com/rniemeyer/knockout-kendo/issues/6

如果有兴趣,那么我可以尝试解决这个问题.

If there is interest, then I could try to get this one resolved.

否则,您可以在绑定中定义dataSource(或传递一个对象).喜欢:

Otherwise, you can define the dataSource in the binding (or pass in an object). Like:

var billingReportViewModel = ko.observable({
    gridDataSource: {data:[{name:"Apple", color:"green"},{name:"Banana", color:"yellow"}]}
});

然后,像这样绑定:

<div id="reportGrid" data-bind="kendoGrid: { data: undefined, dataSource: gridDataSource }"></div>

示例: http://jsfiddle.net/rniemeyer/6SEzp/

这篇关于Kendo-Knockout:与Kendo数据源一起使用基因剔除视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 09:35