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

leading underscore in observable name breaks bind

1 Answer 95 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Sergiu
Top achievements
Rank 1
Sergiu asked on 18 Dec 2012, 05:32 AM
Please reference the attached file.  

Creating an ObservableObject hierarchy yields an Object rather than an Observable for data members that start with the underscore character.

To reproduce, load the attached file, place a break point on line 31 which reads:
var root2 = vm2.get('_root');

Observe that root1 and root2 have been created using identical techniques, except that root2 has a member who's name starts with the underscore (i.e. _root).  Observe that root1 is an observable while root2 is an object.  Step over this line and note that the bind to the change event fails because root2 is not an observable.

How can one build a viewmodel when some members of the object hierarchy start with an underscore?

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 18 Dec 2012, 08:40 AM
Hello Curt,

Indeed this is expected and it is by design. Fields with underscore will be considered as "private" and will not be converted to ObservableObject. This is designed as mechanism to instruct the ObservableObject wrapping logic, to skip certain fields.

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