Is it possible to bind one ViewModel to multiple Views ?

2 posts, 1 answers
  1. Eyal
    Eyal avatar
    4 posts
    Member since:
    Jun 2014

    Posted 22 Jun 2015 Link to this post

    Hi,

    the following code working fine, can somebody verify that this will not be a problem in future version ? 

    Thanks, 

       <h1>MVVM Demo</h1>
        
       <div id="studentview">
           <input data-bind="value: name" />
           <input data-bind="value: age" />
           <button data-bind="click: sayHello">Student Say Hello</button>
       </div>
     
       <div id="teacherview">
           <input data-bind="value: name" />
           <input data-bind="value: age" />
           <button data-bind="click: sayHello2">Teacher Say Hello</button>
       </div>
     
     
    $(document).ready(function () {
     
               var studentViewModel = kendo.observable({
                   name: "Dhananjay Kumar",
                   age : 30 ,
                   sayHello: function () {
                       var name = this.get("name");
                       var age = this.get("age");
                       alert("Hello, " + name + "You are" + age + "Years Old") ;
                   },
                   sayHello2: function () {
                       var name = this.get("name");
                       var age = this.get("age");
                       alert("Hellooooooo, " + name + "You are" + age + "Years Old") ;
                   }               
               });
     
               kendo.bind($("#studentview"), studentViewModel);
               kendo.bind($("#teacherview"), studentViewModel);
         
    });

  2. Answer
    Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 24 Jun 2015 Link to this post

    Hi Eyal,

    This is a working scenario. You may use the approach with future versions of Kendo UI.

    Regards,
    Alexander Valchev
    Telerik
     
    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
Back to Top