I have this code in coffeescript :
render: (collectionName)=>
console.log "I am rendering"
@buildBreadcrumb(collectionName)
buildBreadcrumb: (collectionName) ->
i=0
_.each @urlParts, (url_part) =>
i++
console.log('value of i : ',i)
collection = @getCollection(collectionName)
if (collection.length == 0)
collection.fetch({
success: (collection) =>
@render()
})
else
@appendBreadcrumb()
And I don’t understand why, sometimes, i got an output as :
I am rendering
value of i : 1
value of i : 2
value of i : 3
/* STRANGE START HERE */
value of i : 2
value of i : 3
This problem disappears if i remove the @render() on the fetch success. It’s like the _each loop starts again… But why?
And if i put @render on the “complete” callback, everything works fine.
render: (route)=>
console.log "I am rendering"
@buildBreadcrumb()
buildBreadcrumb: ->
i=0
_.each @urlParts, (url_part) =>
i++
console.log('value of i : ',i)
collection = Proscale.Collections.getCollection(collectionName)
collection.fetch({
complete: (collection) =>
@render()
})
try this,