【问题标题】:Kendo UI Grid , Durandal剑道UI网格,Durandal
【发布时间】:2013-10-23 11:04:42
【问题描述】:

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

我已按照 Durandal Docs 的建议实施

Main.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');
    });
});

Welcome.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 } },
                }
            }
        }
    });

});

Welcome.html

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

【问题讨论】:

  • 不确定是否还有其他问题,但至少您必须在 var roleDataSource =... 首次用于 var vm = ... 之前移动它

标签: jquery asp.net html kendo-ui durandal


【解决方案1】:
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 

【讨论】:

  • 嗨 Jayantha,非常感谢您的帮助,不能将 Datasoruce 称为 dataSource: roleDataSource ,其中 roleDataSource 被取消为 var some where
  • 你也应该按照@RainerAtSpirit 的建议去做。在返回之前定义它。
  • 难道不能像这样在Js文件中声明网格并绑定
    对于 KoGrid
  • 那么你应该有一个名为 kendoGrid 的剑道自定义绑定。在某处定义。
猜你喜欢
  • 1970-01-01
  • 2013-09-24
  • 2015-11-11
  • 2014-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多