我有一个Backbone模型,我想用一些选项进行初始化:
Payment.Payment = Backbone.Model.extend
initialize: (attributes, options) ->
@user = options.user
这些付款是通过付款收集从服务器获取的
# Collections: Payments
Payment.Payments = Backbone.Collection.extend
model: Payment.Payment
url: 'api/payments'
initialize: (models, options) ->
@user = if options?.user then options.user else app.user
但是,当我尝试从服务器获取一组付款时,我无法找到将用户选项传递给每个付款模式的方法:
payments = new Payment.Payments
payments.fetch()
我尝试将用户选项作为参数传递给fetch调用,但这不起作用。那么如何实例化与用户一起从服务器获取的所有支付模型?
答案 0 :(得分:6)
你应该尝试过最简单的方法:
payments.fetch user: payments.user
// have no idea what I'm doing
在JS ^^:
payments.fetch({user: payments.user});
您传递的选项将被提供给模型。