0
votes

Having seen it in a couple of tutorials, I'm trying to execute the following line of code in my view

@model.on('change', @render, this)

Unfortunately the change event is not firing and therefore my view is not re-rendering.

I've tried binding to different events and creating a couple of custom events using the trigger function but nothing seems to be firing at all on the model. Furthermore, there are no errors coming from the console. The change event is working fine on a different collection. I'm using Zepto 1.0, Backbone.js 0.9.2 and Underscore.js 1.3.1

EDIT: I'm trying to execute the following from the Router

  place: (id) ->
    @model = new GM.Models.Place({id: "#{id}"})
    @model.fetch
    view = new GM.Views.Place(model: @model)
    $('#container').html(view.render().el)

And my model is set up like this:

class GM.Models.Place extends Backbone.Model
  urlRoot: '/mobile/place'

I am wondering if anyone has experienced similar problems before and has a quick fix. If not and you need more of the code to find an explanation please let me know...

1
What is executing that you are expecting would fire a change event?bvulaj
I'm expecting that fetching a specific model should fire a change event, as per the code added above. Any thoughts?socratic_singh
Calling .fetch() does. Try it, as explained in @mu's answer.bvulaj

1 Answers

1
votes

You're not actually calling the @model.fetch method anywhere. This:

@model.fetch

is not a method call, you need to add parentheses or arguments if you want to call the method:

@model.fetch()
# or
@model.fetch success: -> ...
# etc.

Otherwise you're just producing this.model.fetch; in the JavaScript and that doesn't do anything useful.