0

I have a composite view which has a task, and it's comments. I put it onto a contentRegion to display. When rendering model alone, it works fine. However when come to collection, it behaves really strange. console.log shows initialize function has been triggered twice. The first time is when define the view

taskView = new MyProject.Views.Task
  model : task
  collection : comments

I then do a MyProject.contentRegion.show(taskView) in order to render the model view. After that, I just call comments.fetch() to get all the comments. Then comes the problem, it re-initialized my taskView and the template keep complaining xxx is undefined.

Any thoughts? I know it's weird because another CompositeView in my project works great.

yujingz
  • 2,271
  • 1
  • 25
  • 29

1 Answers1

1

NathanInMac, I've done a little testing from your suggestion of using an itemView and found some interesting stuff.

Was your problem involving nested compositeviews'? As mine was but I'm unsure if that affects anything.

What solved the problem was initially trying a collectionView which couldn't find the itemView so I moved the definition of the itemView for the collectionView/compositeView to before the definition of the collectionView(or extended).

This seems to be a working fix and just a misleading bug with compositeView's double initializing instead of displaying some exception or error.

  • Thanks Thomas. My solution is in the new item view, add an "change" event for my model, and in the callback, reset the collection model. Then the collection's reset event will be triggered. Do whatever you want to the collection in this callback afterwards. – yujingz Feb 25 '13 at 17:17