I have a spine.js application where I am trying to fetch a list of users who recently commented on the site. My server path is /users/recently_commented.
I tried creating a class method:
Spine.js Video Model
class App.User extends Spine.Model
@configure 'User', 'name'
@extend Spine.Model.Ajax
@recentlyCommented: ->
$.get @url("recently_commented")
When I pass User.recentlyCommented to my view it returns undefined.
How would I fetch those records?
I think you have some problems with how you're calling
$.get.First of all,
$.getis asynchronous soUser.recentlyCommentedwill return ajqXHRrather than a list of User instances.Secondly, you should be calling
$.getwith a callback function of some sort to process therecently_commenteddata when it arrives:Your view will also need to listen for "new model" created events somehow as the Users won't exist until some time after
$.get(and thusrecentlyCommented) returns.Sorry but I don't know Spine so I don't know what the idiomatic approach is here.