Add a sub viewmodel at run time;

15 views
Skip to first unread message

mauro larese

unread,
May 4, 2014, 3:21:37 PM5/4/14
to gl...@googlegroups.com
Hi .. one more question :)
Is it possible to add a view model at runtime?

example :



defModel('modelA',{
     var1:null,
     var2:null,
     ...............

}) 


defModel('modelB',{
     var3:null,
     var4:null,
     modelASubView:null
     ...............

}) 


var mavm = glu.model({ xtype:''modelA' })

......  //do something with  mavm
.....

var mbvm = glu.model({ xtype:''modelB'  ,   modelASubView: mavm  })


my problem is that the first model it is not really integrated in the second model view (for example parentVM and rootVM are not well initialized)

there is any way to do it ?

thanks in advance

- Mauro

Ryan Smith

unread,
May 5, 2014, 5:37:57 PM5/5/14
to gl...@googlegroups.com
You can totally setup the submodels at runtime.  For example you would say something inside of viewmodel A like:

this.model({mtype: 'modelB'})

That will configure the parent/child relationship so that modelB has a parentVM of parentA.

Hopefully that helps!

-Ryan


--
You received this message because you are subscribed to the Google Groups "GluJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glujs+un...@googlegroups.com.
To post to this group, send email to gl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glujs/2d9931d9-cd97-4f55-b543-f7e6d8796df4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mauro larese

unread,
May 6, 2014, 2:17:34 AM5/6/14
to gl...@googlegroups.com
sorry, may be may question was not clear.

I need an already existing instance of a model  to become a sub model not a new one.


Ryan Smith

unread,
May 6, 2014, 9:12:14 AM5/6/14
to gl...@googlegroups.com
I'm sorry I mis-understood the question.  You can totally move models around and make them sub-models no problem.  If you need to take an existing model from one list to another, there is a "transfer" function on the list that will allow you to pull the viewmodel from one list to another.

You can also move the model to another model no problem by just moving it and setting the property on the viewmodel.  If you are seeing errors or something, its likely that GluJS is complaining about the parentVM already existing or being associated to another viewmodel... in which case there is an "unparent" function on the viewmodel which will allow you to disconnect the viewmodel from its current parent, and then you can re-attach it to the new viewmodel.

If you have a specific case or anything, I could be more helpful.  The only time I've moved viewmodels around is when they are in a list, so knowing the use case I might be able to give you some useful code that would help you out.  Sorry about the confusion :)

-Ryan


Reply all
Reply to author
Forward
0 new messages