I have a Backbone Model which I want to initialize with some options:
Payment.Payment = Backbone.Model.extend
initialize: (attributes, options) ->
@user = options.user
These Payments are fetched from the server through a Payment Collection
# 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
When I try to fetch a set of payments from the server, however, I can't find a way to pass the user option to each of the Payment models:
payments = new Payment.Payments
payments.fetch()
I've tried passing in a user option as a parameter to the fetch call, but that doesn't work. How then can I instantiate all the payment models fetched from the server with the user?
You should have tried the simplest:
payments.fetch user: payments.user
// have no idea what I'm doing
In JS ^^:
payments.fetch({user: payments.user});
The options you pass fetch will be given to the models.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With