Angular:如何在全班中访问$ scope.gridData?

时间:2014-06-18 13:51:46

标签: javascript angularjs class-variables

我有这段代码:

orders.controller('OrdersCtrl', function ($scope, $http, $rootScope, $location, $notification, $routeParams) {

        // this works
        $scope.initGrid = function () {
              $scope.gridData = new kendo.data.ObservableArray([
                { artist: "Pink Floyd", track: "The dark side of the Moon" },
                { artist: "The Beatles", track: "I've just seen a face" },
                { artist: "Queen", track: "Innuendo" }
              ]);

              $scope.gridColumns = [
                { field: "artist", title: "Artist" },
                { field: "track", title: "Track" }
              ];

        };
        // this does not working
        $scope.update = function() {
                $scope.gridData[0].set("track", "Hey you");
        };

    });

点击模板中的按钮后:

<button kendo-button ng-click="update()">
  Update from code
</button>

我总是遇到以下异常:

TypeError: Cannot read property '0' of undefined

问题是:

如何从其他方法访问范围网格数据?

感谢您的任何建议。

0 个答案:

没有答案
相关问题