0

http://jsfiddle.net/maxl/tNZAm/102/

我希望中继器列出这个数组:

函数 MyControl(){ var self = this;

self.values = ["a","b","c","d","e","f"];
self.selectedIndex = -1;

self.toggleSelect = function(ind){
    if( ind === self.selectedIndex ){
        self.selectedIndex = -1;
    } else{
        self.selectedIndex = ind;
    }
}

self.getClass = function(ind){
    if( ind === self.selectedIndex ){
        return "selected";
    } else{
        return "";
    }
}

self.getButtonLabel = function(ind){
    if( ind === self.selectedIndex ){
        return "Deselect";
    } else{
        return "Select";
    }
} }​
4

1 回答 1

1

您应该使用$scope可注入将数据附加到 DOM。此外,您加载了 Angular.js 两次(一次通过“选择框架”下拉菜单,一次通过“添加资源”面板),导致了一个非常非常奇怪的错误。

这是一个有效的 jsFiddle:http: //jsfiddle.net/BinaryMuse/tNZAm/103/

function MyControl($scope){
    $scope.values = ["a","b","c","d","e","f"];
    $scope.selectedIndex = -1;

    $scope.toggleSelect = function(ind){
        if( ind === $scope.selectedIndex ){
            $scope.selectedIndex = -1;
        } else{
            $scope.selectedIndex = ind;
        }
    }

    $scope.getClass = function(ind){
        if( ind === $scope.selectedIndex ){
            return "selected";
        } else{
            return "";
        }
    }

    $scope.getButtonLabel = function(ind){
        if( ind === $scope.selectedIndex ){
            return "Deselect";
        } else{
            return "Select";
        }
    }
}​
于 2012-12-03T21:25:23.623 回答