This is a migrated thread and some comments may be shown as answers.

How do you dynamically add to the model?

1 Answer 72 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 23 Jan 2013, 02:41 PM
Setup: I have a master model, and my page has a bunch of widgets on it.

So I want to have the widgets powered by MVVM instead of wiring everything up manually in jQuery.

Here's the sample
http://jsbin.com/epijuw/3/edit

So what am I doing wrong here?...why is the event not firing?

1 Answer, 1 is accepted

Sort by
0
Holger
Top achievements
Rank 1
answered on 24 Jan 2013, 07:54 AM
Hi Steve,

I guess the problem is that layoutViewModel.gadgets.widget1 is not initialized at the time when the HTML is loaded, so the binding will not work. After adding an event handler to the root model and calling gadgets.widget1.doneloading inside it everything works fine.

Please have a look at the modified sample: http://jsbin.com/epijuw/19/edit

HTH,
Holger
Tags
MVVM
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Holger
Top achievements
Rank 1
Share this question
or