バックボーンコレクションを取得しようとして少し立ち往生しています。私はバックボーンに不慣れで、簡単なものを見逃していると確信していますが、何がわかりません。
アイデアはありますか?
$ ->
User = Backbone.Model.extend(
urlRoot: "/users"
)
user = new User()
View = Backbone.View.extend(
tagName: "li"
el: "ul"
id: "#users"
template: _.template("<li>...just a code...<span class='buttons'><button class='info'>Info</button><button class='delete'>Delete</button></span></li>")
render: ->
@$el.html(@template())
)
view = new View(
model: user
)
view.render().el
Users = Backbone.Collection.extend(
model: User
url: "/users"
parse: (resp, xhr) ->
return resp.toJSON()
)
usersCollection = new Users()
usersCollection.fetch(
success: (response) ->
console.log 'success'
console.log usersCollection
console.log response
error: (data, response) ->
console.log(response)
)
私の "/users/ はこの配列を返します:
[{"created_at":"2013-05-25T18:00:43Z","email":"user1@mail.ru","id":1,"updated_at":"2013-05-25T18:00:43Z"},{"created_at":"2013-05-25T18:00:43Z","email":"user2@mail.ru","id":2,"updated_at":"2013-05-25T18:00:43Z"},{"created_at":"2013-05-25T18:00:43Z","email":"user3@mail.ru","id":3,"updated_at":"2013-05-25T18:00:43Z"},{"created_at":"2013-05-25T18:00:43Z","email":"user4@mail.ru","id":4,"updated_at":"2013-05-25T18:00:43Z"},{"created_at":"2013-05-25T18:00:43Z","email":"user5@mail.ru","id":5,"updated_at":"2013-05-25T18:00:43Z"},{"created_at":"2013-05-25T18:00:43Z","email":"user6@mail.ru","id":6,"updated_at":"2013-05-25T18:00:43Z"},{"created_at":"2013-05-25T18:00:43Z","email":"user7@mail.ru","id":7,"updated_at":"2013-05-25T18:00:43Z"}]
コントローラー (Ruby on Rails) は次のようになります。
def index
users = User.all
render json: users, status: 200
end
そしてconsole.logには次のものがあります:
success
child {length: 1, models: Array[1], _byId: Object, constructor: function, model: function…}