我是一種新的backbone.js,我很努力地用belongs_to關係獲取一個集合。處理與backbone.js的belongs_to關係
我想獲取用戶列表(用戶/ GET),我想用belongs_to關聯來顯示它們。
例如顯示用戶的公司名稱。有人知道一個解決方案?
我使用Ruby on Rails的3使用CouchDB
用戶控制器
def index
User.all
end
骨幹收集
class UserCollection extends Backbone.Collection
url: ->
app.routes.users_url
model: User
骨幹模型
class User extends Backbone.Model
idAttribute: '_id'
defaults: {
"email": null
"mobile": null
"loc": null
}
url: ->
app.routes.users_url + '/' + (@id || '')
我想展示COM帕尼名像這樣...
%script{:id => "user-resource-template", :type => "text/template"}
%td= check_box_tag "select", 1, false, :class => "checkbox", "data-id" => raw("<%= _id %>")
%td <%= name %>
%td <%= email %>
%td <%= company.name %>
那麼有什麼不能正常工作? –
那麼屬於關係不是工作,這是課程的邏輯,因爲模型沒有任何關係。所以我不知道如何打印company.name –