0

我正在尝试将 Kendo UI Grid 与 Durandal 2.0.1 一起使用,但 API 调用未发送且 Grid 根本没有出现,请让我知道我做错了什么。

我已按照 Durandal Docs 的建议实施

主.js

requirejs.config({
    paths: {
        'text': '../Scripts/text',
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',
        'transitions': '../Scripts/durandal/transitions'
    }
});

define('jquery', function() { return jQuery; });
define('knockout', ko);

define(['durandal/system', 'durandal/app', 'durandal/viewLocator', 'durandal/binder'], function (system, app, viewLocator, binder) {
    //>>excludeStart("build", true);
    system.debug(true);
    //>>excludeEnd("build");

    app.title = 'Durandal Starter Kit';

    app.configurePlugins({
        router: true,
        dialog: true,
        widget: true
    });

    app.start().then(function() {
        //Replace 'viewmodels' in the moduleId with 'views' to locate the view.
        //Look for partial views in a 'views' folder in the root.
        viewLocator.useConvention();

        // As per http://durandaljs.com/documentation/KendoUI/
        kendo.ns = "kendo-";
        binder.binding = function (obj, view) {
            kendo.bind(view, obj.viewModel || obj);
        };
        //Show the app by setting the root view model for our application with a transition.
        app.setRoot('viewmodels/shell', 'entrance');
    });
});

欢迎.js

define(function() {

    var vm = {
        displayName: 'Roles',
        gridOptions:{
            dataSource: roleDataSource,
            height: 700,
            toolbar: [{ name: "create", text: "Add New Role" }],
            columns: [
                { field: "Name", title: "Name" },
                { field: "Description", title: "Description" },
                { field: "Key", title: "Key" }
               ],

        }
};

    return vm;

    var roleDataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: "http://tvaiswb01/api/role/GetRoles",
                dataType: "json"
            },
            parameterMap: function (data, operation) {
                return JSON.stringify(data);
            }
        },
        batch: false,
        error: error,
        pageSize: 20,
        requestEnd: roleDataSource_requestEnd,
        schema: {
            model: {
                id: "Id",
                fields: {
                    Id: { editable: false, nullable: true },
                    Name: { validation: { required: true } },
                    Description: { validation: { required: false } },
                    Key: { validation: { required: false } },
                }
            }
        }
    });

});

欢迎.html

<section>
    <h2 data-bind="html:displayName"></h2>
    <div data-kendo-bind="kendoGrid: gridOptions" id="roleGrid"></div>
</section>
4

1 回答 1

4
define(function() {

    var vm = {
        displayName: 'Roles',
        dataSource: new kendo.data.DataSource({
           transport: {
             read: {
                url: "http://tvaiswb01/api/role/GetRoles",
                dataType: "json"
             },
             parameterMap: function (data, operation) {
                return JSON.stringify(data);
             }
          },
           batch: false,
           error: error,
           pageSize: 20,
           requestEnd: roleDataSource_requestEnd,
           schema: {
            model: {
                id: "Id",
                fields: {
                    Id: { editable: false, nullable: true },
                    Name: { validation: { required: true } },
                    Description: { validation: { required: false } },
                    Key: { validation: { required: false } },
                }
            }
         }
     });
};

    return vm;
}

在 HTML 中你可以定义配置,(我只使用了高度,你可以定义其他配置,像这样在 HTML 中的事件)

<section>
    <h2 data-bind="html:displayName"></h2>
    <div data-kendo-bind="source: dataSource"  data-kendo-height="700"  id="roleGrid" data-kendo-role='grid'></div>
</section>

编辑

如果您的数据源需要在外部定义,您可以像这样返回它,

 displayName: 'Roles',
 dataSource:roleDataSource 
于 2013-10-23T11:29:43.293 回答