KoGrid无法在Durandal JS框架中工作

KoGrid not working in Durandal JS framework

本文关键字:框架 工作 JS Durandal KoGrid      更新时间:2023-09-26

如何在durandal JS视图页面中绑定koGrid。下面给出的代码不起作用。

查看(html)

  <div id="functiontable" class="form-actions">
                        <div style="height: 200px" data-bind="koGrid: {
                                 data: items, columnDefs: [{ field: 'id', width: 140 },
                                    { field: 'name', width: 100 },
                                    { field: 'price', width: 150 }
                                ],
                            autogenerateColumns: false,
                            isMultiSelect: false,
                             enableSorting: true
                        }"></div>
                    </div>

viewmodel(js)

define([ 'repositories/customerRepository', 'plugins/router', 'plugins/http', 'durandal/app', 'knockout'], function (customerRepository, router, http, app, ko) {
var items = ko.observableArray([
 { id: 1, name: "abc", price: "asds" },
{id:1,name:"abc",price:"asds"},
]);
return {
    router: router,
    items:items, 
    activate: function () {

    },
    attached: function (view) {
    },

};});

如果从浏览器中检查图元,则轴网将加载其值。我不知道如何解决这个问题。有人能帮我吗?

项目实际上需要返回才能被视图使用,所以:

items: ko.observableArray([
       { id: 1, name: "abc", price: "asds" },
       {id:1,name:"abc",price:"asds"}
]),
activate: function () {
}

提示在做这些事情时,请使用客户端调试器,如Chrome web工具(Chrome中的F12),这将突出显示找不到"项目"。