【问题标题】:Remote Datasource and Remote Views + MVVM远程数据源和远程视图 + MVVM
【发布时间】:2014-02-10 04:02:58
【问题描述】:

我试图在 Kendo Mobile 应用程序(即不是 MVC)中分离我的视图和视图模型。我在 ViewModel 中有一个远程数据源,但无法让它工作 - 我确信这很简单(我找不到在 ViewModel 中使用远程数据源的 Kendo 示例 - 它都是内联的。(http://demos.telerik.com/kendo-ui/web/mvvm/remote-binding.html, http://docs.telerik.com/kendo-ui/getting-started/framework/datasource/overview)

它只显示这个“函数 (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 视图模型

(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);

【问题讨论】:

    标签: mvvm kendo-ui telerik datasource


    【解决方案1】:

    我找到了一个例子并设法让它工作,尽管 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);
    

    【讨论】:

    • ps - 我不太明白这里的区别 - kendo.data.ObservableObject.extend 这第二段代码似乎是在扩展初始化事件 - 我实际上需要在另一个上公开远程数据源事件(例如点击按钮)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多