0

Knockout と CodeIgniter で MySQL データベースからすべてのユーザーを表示しようとしています。サーバーから json 応答が返ってきましたが、Knockout が Json データを表示していません。

私は得続けます:

Uncaught ReferenceError: バインディングを解析できません。バインディング値: テキスト: id メッセージ: id が定義されていません

HTML:

<!-- Users -->
<table class="table table-condensed table-striped table-bordered table-hover">
    <thead>
        <tr><th>User Id</th><th>Name</th><th>Email</th><th>Role</th></tr>
    </thead>
    <tbody data-bind="foreach: users">
        <tr>
            <td data-bind="text: id"></td>
            <td><input data-bind="value: name" /></td>
            <td><input data-bind="value: email"/></td>
            <td><select data-bind="options: $root.roles, value: role, optionsText: 'role', optionsValue: 'role'"></select></td>
            <td><a href="#" data-bind="click: $root.removeUser" class='icon-remove'></a></td>
        </tr>         
        </tr>
    </tbody>
</table>


<pre data-bind="text: ko.toJSON($data, null, 2)"></pre>

ノックアウト:

<script type="text/javascript">
    function User(data) {
        this.name = ko.observable(data.name);
        this.email = ko.observable(data.email);
        this.id = ko.observable(data.id);
        this.role = ko.observaveble(data.role);
    }

    function UserListViewModel(data) {
        // Data
        var self = this;
        self.users = ko.observableArray([]);


        // Operations
        self.addTask = function() {
            self.tasks.push(new Task({title: this.newTaskText()}));
            self.newTaskText("");
        };
        self.removeTask = function(task) {
            self.tasks.remove(task)
        };

        // Load initial state from server, convert it to Task instances, then populate self.tasks
        $.get("/sws/users/index", function(data) {
            var mappedUsers = ko.mapping.fromJSON(allData);
            self.users(mappedUsers);
        });
    }

    ko.applyBindings(new UserListViewModel());
</script>

ジョンソン:

{"users":[{"id":"1","email":"example@gmail.com","password":"tacos","permissions":null,"activated":"1","activation_code":null,"activated_at":"2013-09-23 20:19:42","last_login":"2013-09-23 20:19:42","persist_code":null,"reset_password_code":null,"name":"Chris","created_at":"2013-09-23 04:17:24","updated_at":"2013-09-23 07:16:23"}]}
4

2 に答える 2