0

各行を選択してテーブルを作成しようとしています。テーブルからのデータと選択フィールドは配列からのものです...

<div ng-app="app" ng-controller="MainCtrl">
<table>
    <thead>
        <tr>
            <th>Headline #1</th>
            <th>Headline #2</th>
            <th>Headline #3</th>
            <th>Headline #4</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="user in users">
            <td>{{user.id}}</td>
            <td>{{user.name}}</td>
            <td>
                <select name="" id="">
                    <option value="" ng-repeat="role in roles">{{role.name}}</option>
                </select>
            </td>
            <td>anything...</td>
        </tr>
    </tbody>    
</table>

angular.module('app', [])
.controller('MainCtrl', function ($scope) {

        $scope.users = [
            {
                id : 1,
                name : 'Andrew',
                role : "admin"
            },
            {
                id : 2,
                name : 'Tanya',
                role : "admin"
            },
            {
                id : 3,
                name : 'Roland',
                role : "author"
            },
        ];

        $scope.roles = [
            {
                name : "author"
            },
            {
                name : "admin"
            }

        ];



});

ここで私の例を参照してください: jsFiddle

私が必要とするのは簡単です。各ユーザーには役割があり、各行に正しい役割が選択されるようにしたいと思います...

私の非常に悪い英語で申し訳ありません...

thxネイサン

4

1 に答える 1

0

idこのように役割データリストのフィールドを追加します

$scope.roles = [{
    id: "author",
    name: "author"
}, {
    id: "admin",
    name: "admin"
}];

select要素を次のように変更します

<select ng-model="user.role" ng-options="role.id as role.name for role in roles"></select>

Demo on jsFiddle

于 2013-07-30T22:29:10.660 に答える