Skip to content

Instantly share code, notes, and snippets.

@tommyp
Last active December 23, 2015 17:19
Show Gist options
  • Save tommyp/6668117 to your computer and use it in GitHub Desktop.
Save tommyp/6668117 to your computer and use it in GitHub Desktop.
class Shsh.Views.AssetsIndex extends Backbone.View
template: JST['assets/index']
initalize: ->
@collection.on('reset', @render, this)
render: ->
$(@el).html(@template(assets: @collection))
console.log('rendered')
this
class Shsh.Routers.Assets extends Backbone.Router
routes:
'': 'index'
initialize: ->
@collection = new Shsh.Collections.Assets()
@collection.fetch({reset: true})
index: ->
view = new Shsh.Views.AssetsIndex(collection: @collection)
$('#container').html(view.render().el)
h1 Hiya!!
p = @assets.length
[{"created_at":"2013-09-19T14:28:37Z","id":1,"title":"Asset 0","updated_at":"2013-09-19T14:28:37Z"},{"created_at":"2013-09-19T14:28:37Z","id":2,"title":"Asset 1","updated_at":"2013-09-19T14:28:37Z"},{"created_at":"2013-09-19T14:28:37Z","id":3,"title":"Asset 2","updated_at":"2013-09-19T14:28:37Z"},{"created_at":"2013-09-19T14:28:37Z","id":4,"title":"Asset 3","updated_at":"2013-09-19T14:28:37Z"},{"created_at":"2013-09-19T14:28:37Z","id":5,"title":"Asset 4","updated_at":"2013-09-19T14:28:37Z"},{"created_at":"2013-09-19T14:28:37Z","id":6,"title":"Asset 5","updated_at":"2013-09-19T14:28:37Z"},{"created_at":"2013-09-19T14:28:37Z","id":7,"title":"Asset 6","updated_at":"2013-09-19T14:28:37Z"},{"created_at":"2013-09-19T14:28:37Z","id":8,"title":"Asset 7","updated_at":"2013-09-19T14:28:37Z"},{"created_at":"2013-09-19T14:28:37Z","id":9,"title":"Asset 8","updated_at":"2013-09-19T14:28:37Z"},{"created_at":"2013-09-19T14:28:37Z","id":10,"title":"Asset 9","updated_at":"2013-09-19T14:28:37Z"}]
@tommyp
Copy link
Author

tommyp commented Sep 23, 2013

So the view gets rendered, @assets.length comes back as zero, but there's 10 in the DB. Maybe I'm wrong, but wouldn't the console.log('rendered') come back twice?

If I trigger all the steps manually in the console, it gets updated with 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment