远程数据源和远程视图+ MVVM

时间:2014-02-10 04:02:59

标签: mvvm kendo-ui telerik datasource

我试图在Kendo Mobile应用程序中分离我的Views和ViewModels(即不是MVC)。我在ViewModel中有一个远程数据源,无法使其工作 - 我确信它很简单(我找不到在ViewModel中使用远程数据源的Kendo示例 - 它都是内联的。({{3} },http://demos.telerik.com/kendo-ui/web/mvvm/remote-binding.html

它只显示了这个“函数(e){var n = this; return e === t?n._data:(n._data = this._observe(e),n._ranges = [],n。 _addRange(n._data),n._total = n._data.length,n._process(n._data),t)}“而不是实际数据。

games.html查看

<div id="tabstrip-home"
     data-role="view"
     data-title="Games"
     data-model="app.gamesService.viewModel">

    <ul class="games-list"               
         data-bind="source: gamesDataSource"
         data-template="template">
    </ul>

</div>

<script type="text/x-kendo-template" id="template">
    <div class="product">
        <h3>#:ProductName#</h3>
        <p>#:kendo.toString(UnitPrice, "c")#</p>
    </div>
</script>

games.js ViewModel

(function (global) {
    var GamesViewModel, app = global.app = global.app || {};
 
    GamesViewModel = kendo.data.ObservableObject.extend({
                                                            gamesDataSource: new kendo.data.DataSource({
                                                                                                           transport: {
                                                                    read: {
                                                                                                                   url: "http://demos.telerik.com/kendo-ui/service/Products",
                                                                                                                   dataType: "jsonp"
                                                                                                               }
                                                                }
                                                                                                       })
                                                             
                                                        });
    app.gamesService = {
        viewModel: new GamesViewModel()
    };
})(window);

1 个答案:

答案 0 :(得分:0)

我找到了一个例子,并设法让这个工作,虽然javascript有点不同。我必须阅读

(function (global) {
    var GamesViewModel,
        app = global.app = global.app || {};

    GamesViewModel = kendo.data.ObservableObject.extend({
        gamesDataSource: null,

        init: function () {
            var that = this,
                dataSource;

            kendo.data.ObservableObject.fn.init.apply(that, []);

            dataSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: "http://demos.telerik.com/kendo-ui/service/Products",
                        dataType: "jsonp"

                        //ProductID":1,"ProductName":"Chai","UnitPrice":18,"UnitsInStock":39,"Discontinued":false

                    }
                }
            });

            that.set("gamesDataSource", dataSource);
        }
    });

    app.gamesService = {
        viewModel: new GamesViewModel()
    };
})(window);