Retrieveing ViewModel from Element

4 posts, 0 answers
  1. Patrick
    Patrick  avatar
    10 posts
    Member since:
    Nov 2011

    Posted 31 Oct 2012 Link to this post

    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
  2. Brandon
    Admin
    Brandon avatar
    21 posts

    Posted 31 Oct 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Stephen
    Stephen avatar
    40 posts
    Member since:
    Jul 2008

    Posted 28 Aug 2015 in reply to Brandon Link to this post

    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

  5. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 01 Sep 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready