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

Is it possible to bind one ViewModel to multiple Views ?

1 Answer 132 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Eyal
Top achievements
Rank 1
Eyal asked on 22 Jun 2015, 01:55 PM

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);
     
});

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 24 Jun 2015, 03:35 PM
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!
 
Tags
MVVM
Asked by
Eyal
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or