0

我正在使用带有更新的 durandal 和 jquery nuget 包的 Visual Studio 2012 Update 2 hottowel 模板...

这是我的代码:Durandal main.js:

require.config({
    paths: { "text": "durandal/amd/text" }
});

define(['durandal/app', 'durandal/viewLocator', 'durandal/viewModelBinder', 'durandal/system', 'durandal/plugins/router', 'services/logger'],
    function (app, viewLocator, viewModelBinder, system, router, logger) {

    // Enable debug message to show in the console 
    system.debug(true);

    app.start().then(function () {
        toastr.options.positionClass = 'toast-bottom-right';
        toastr.options.backgroundpositionClass = 'toast-bottom-right';

        router.handleInvalidRoute = function (route, params) {
            logger.logError('No Route Found', route, 'main', true);
        };

        // When finding a viewmodel module, replace the viewmodel string 
        // with view to find it partner view.
        router.useConvention();
        viewLocator.useConvention();

        // Adapt to touch devices
        app.adaptToDevice();

        kendo.ns = "kendo-";
        viewModelBinder.beforeBind = function (obj, view) {
            kendo.bind(view, obj.viewModel || obj);
        };
        //Show the app by setting the root view model for our application.
        app.setRoot('viewmodels/shell', 'entrance');
    });
});

杜兰达尔视图模型:

define(['services/datacontext', 'durandal/plugins/router'],
    function (datacontext, router) {


        var activate = function () {
            //yes yes - I will separate this out to a datacontext - it is here for debugging simplicity
            var service = $data.initService("https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase/");
            //return promise as durandal seems to want...
            return service.then(function (db) {
                vm.set("airports", db.Airport.asKendoDataSource());
            });

        };



        var deactivate = function () {
        };

        var viewAttached = function (view) {
            //kendo.init($("#airportGrid"));
            //kendo.bind(view, vm);
            //kendo.bind($("#airportGrid"), vm);
        };

        var vm = new kendo.data.ObservableObject({
            activate: activate,
            deactivate: deactivate,
            airports: [],
            title: 'Airports',
            viewAttached: viewAttached
        });

        return vm;
    });

杜兰达尔观点:

<section>
    <h2 class="page-title" data-bind="text: title"></h2>
    <div id="airportGrid" data-kendo-role="grid" data-kendo-sortable="true" data-kendo-pageable="true" data-kendo-page-size="25" data-kendo-editable="true" data-kendo-columns='["id", "Abbrev", "Name"]' data-kendo-bind="source: airports"></div>    
</section>

我在 Chrome 的网络监视器中看到对 jaystack 的调用: https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase//Airport? $inlinecount=allpages&$top=25 我看到数据回来了。

kendoui 网格创建得很好,但其中没有数据(我认为这意味着 kendoui 很高兴并且绑定了 MVVM 绑定,但是创建的 kendoui 网格似乎不想理解从 jaydata 创建的 kendoui 数据源)

如果没有 durandal,这可以很好地工作,如下所示:http: //jsfiddle.net/t316/4n62B/29/

我已经尝试了 2 天了 - 有人可以帮我吗?

谢谢TJ

4

2 回答 2

2

在移除了仅微风所需的部件后,听起来一切正常。

不过,我建议稍微重组工作dFiddle 代码,以确保在vm设置之前定义a) 和 b) 无需创建一个无论如何都会被覆盖的虚拟对象。vm.airportsactivatevm.airports kendo.data.DataSource()activate

define(function( ) {

    var vm = new kendo.data.ObservableObject({
      activate: activate,
      deactivate: deactivate,
      // airports: new kendo.data.DataSource(),
      title: 'Airports',
      viewAttached: viewAttached
    });

    return vm;

    function activate () {
      var service = $data.initService("https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase/");
      return service.then(function( db ) {
          vm.airports = db.Airport.asKendoDataSource();
      });

    }

    function deactivate () {
    }

    function viewAttached ( view ) {
      //kendo.init($("#airportGrid"));
      //kendo.bind(view, vm);
      //kendo.bind($("#airportGrid"), vm);
    }

});
于 2013-06-17T10:37:02.203 回答
0

您使用 jQuery 上的哪个版本?尝试使用 1.8.3 或 1.9 + 迁移。在 Chrome 中,将停止标志切换为紫色(单击两次)以捕获未捕获的异常并查看是否有任何异常。

于 2013-06-16T05:15:59.340 回答