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

Parent data accessible via data-bind syntax, but not template syntax

3 Answers 78 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 11 Nov 2015, 11:22 PM

I'm trying to figure out how to access parent level data using template syntax (#: parentId #) as opposed to data-bind="text: parentId" syntax.  The data-bind syntax finds the parent data, but the template syntax does not.  I'm trying to create a path so I cannot use data-bind syntax.  I've created an example to demonstrate the problem here: 

http://jsfiddle.net/MadCodeMonkey/uwf5w83x/

If you remove  #: parentId # from the template, it will work again.

 

I assume that it is supposed to automatically retrieve parent data the way data-bind works, but perhaps it just doesn't work the same way.

3 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 13 Nov 2015, 08:35 AM

Hello Dave,

 

the data-bind approach works because the observables automatically build object hierarchy, necessary for the change detection (and, for that matter, cases like this one) to be handled correctly. Apart from that, a "parent object" concept is not present in the plain javascript objects. They are not "aware" that an object has a reference of them bound to a given field. 

 

 

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Dave
Top achievements
Rank 1
answered on 13 Nov 2015, 03:43 PM

 Petyo,

Thank you.  I just wanted to make sure that I wasn't missing something.  My work around currently is to pass along a copy of the parent fields to the child row objects when they are created on the client side.  It's not ideal, but it works.

 

I did try putting the parent on the child object, but that generates a "Uncaught RangeError: Maximum call stack size exceeded" error.

 

Dave

0
Petyo
Telerik team
answered on 17 Nov 2015, 08:43 AM

Hello Dave,

 

Indeed, this is so - assigning the parent to child will produce circular reference, which in many cases trips the JSON serializer.

 

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