1

我无法弄清楚这里发生了什么。我正在尝试为网格制作自定义指令,并将使用元素属性来自定义给定实例。在这样做时,我制作了两个文件

网格控制器.js

app.controller('gridController', ['$scope', function ($scope ) {

    //Initilization code

    $scope.gridOptions = {
        //Setup options
    };

    $scope.detailOptions = function (e) {
        console.log('winning');
        return {
            dataSource: {
                transport: {
                    read: {
                        url: "/detail" + e.OrderNumber + ".json",
                        dataType: 'json'
                    }
                },
                error: function (e) {
                    console.log(e);
                },
                pageSize: true,
                serverPaging: false,
                serverFiltering: false,
                serverSorting: false,
            },
            columns: [
                    {
                        field: "ItemCode",
                        label: "lblItemCode",
                        title: ""
                    }, {
                        field: "ItemDesc",
                        label: "lblItemDesc",
                        title: ""
                    }, {
                        field: "QuantityOrdered",
                        label: "lblQuantityOrdered",
                        title: ""
                    }
            ],
            scrollable: false,
            sortable: true
        };
    }

}]);

网格指令.js

app.directive('grid', function () {
    return {
        // Restrict E for element
        restrict: 'E',
        // Here we setup the template for the code we want to replace our directive
        template: "<div> \n\
                        <div kendo-grid='grid' \n\
                             k-options='gridOptions'\n\
                             k-data-source='dataSource'>\n\
                        </div> \n\
                        <script type='text/x-kendo-template'\n\
                                id='details'>\n\
                                <div kendo-grid >\n\
                                </div>\n\
                        </script>\n\
                   </div>",
        replace: true,
        scope: {
        },
        controller: "gridController",
        link: function (scope, element, attrs) {

            //Gather some attribute data and set it to the gridOptions object


            if(scope.$eval(attrs.detailsGrid))
            {
                scope.gridOptions.detailTemplate = kendo.template($("#details").html());
                scope.gridOptions.detailInit = scope.detailOptions;
            }

            //More customization code

            scope.dataSource = new kendo.data.DataSource({
                //Setup dataSource options for main grid
            });
        }
    };
});

为了简洁起见,我排除了很多额外的代码。

我的问题是每当我尝试打开行的详细信息时,该行会打开...关闭...并且网格似乎正在刷新。看起来好像有什么东西在崩溃,结果主网格正在刷新。

这是相关的plunkr,其中注释部分充实。

4

1 回答 1

0

因此,在我发布问题后的第二天,angular-kendo 发布了解决此问题的更新。在更新库并修复我的代码后,详细信息网格按预期工作!

于 2014-05-09T13:26:40.480 回答