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

Retrieveing ViewModel from Element

3 Answers 250 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 31 Oct 2012, 12:12 PM
Seems simple enough, but after looking though the threads I can't find an answer.  So, everyone knows you can bind a view model to an element and you can get the validator from an element or most any other kendo object.  But, how do you get the view model bound to the element?  In case the example is unclear, I'm trying to retrieve the viewModel in the getViewModel function w/o using some kind of global variable.

function setViewModel() {
    var viewModel = kendo.observable({name:'John Doe'});
    kendo.bind($("form"), viewModel);
}

function getViewModel() {
    var viewModel = $('#form').kendo(???);
}

<div id="form">
//usual binding stuff
</div>

Thanks,
nick

3 Answers, 1 is accepted

Sort by
0
Brandon
Telerik team
answered on 31 Oct 2012, 01:50 PM
Hi Patrick,

There is no coupling from a bound object to it's observable. Rather, Kendo itself maintains the link between these object. This means that the viewModel itself is not stored in the jQuery data store, as some of the other kendo widgets objects you mention are. The elements themselves contain references to their individual binding properties, but these are binding instructions for Kendo, as opposed to traceable pointers back to the View Model.

If you need to retrieve a reference to the View Model from a form, you can either store the observable in the jQuery data store yourself, or access the object via some other means.

All the best,

Brandon
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Stephen
Top achievements
Rank 2
answered on 28 Aug 2015, 03:08 PM

Would you please post an example of how you would store and then retrieve the viewmodel (ie by "other means")

It would make this a more complete answer, as well as help me out. :)

thanks!

Stephen

0
Petyo
Telerik team
answered on 01 Sep 2015, 09:03 AM

Hello Stephen,

please check this forum thread.

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
MVVM
Asked by
Patrick
Top achievements
Rank 1
Answers by
Brandon
Telerik team
Stephen
Top achievements
Rank 2
Petyo
Telerik team
Share this question
or