2012-05-11 37 views
1

我有一個spine.js應用程序,我正在嘗試獲取最近在網站上發表評論的users列表。我的服務器路徑是/users/recently_commentedSpine.js抓取自定義記錄

我試圖創建一個類的方法:

Spine.js視頻模型

class App.User extends Spine.Model 
    @configure 'User', 'name' 
    @extend Spine.Model.Ajax 

    @recentlyCommented: -> 
    $.get @url("recently_commented") 

當我通過User.recentlyCommented我的看法則返回undefined

我將如何獲取這些記錄?

回答

1

我覺得你有一些問題,你打電話給$.get

首先,$.get是異步的,因此User.recentlyCommented將返回jqXHR而不是User實例列表。

其次,你應該有某種形式的回調函數來調用$.get處理recently_commented數據到達時:

$.get @url('recently_commented'), (data) -> 
    # Now convert 'data' to User model instances, 
    # if this function cares about its context then 
    # you'll probably want to use => to define it. 

您的觀點也將需要以某種方式爲偵聽「新模式」創建活動在$.get(並因此recentlyCommented)返回之後的某個時間,用戶將不存在。

對不起,但我不知道脊椎,所以我不知道這裏的慣用方法是什麼。