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

Binding to multiple view models nested in the Dom.

2 Answers 368 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 22 Feb 2013, 06:01 AM
Hi,

I am trying to bind a model to a higherlevel element and then later bind another model to something nested deeper in the dom.

When I do this, i get the following stack trace:
  1. Uncaught TypeError: Cannot read property 'parent' of undefined kendo.all.js:8419
    1. binders.source.Binder.extend.renderkendo.all.js:8419
    2. binders.source.Binder.extend.refreshkendo.all.js:8332
    3. Class.extend.bindkendo.all.js:8158
    4. Class.extend.applyBindingkendo.all.js:8954
    5. Class.extend.bindkendo.all.js:8930
    6. window.CubeBrowserModelBinder.CubeBrowserModelBinder.bindcubebrowser.model.binder.js:15
    7. CubeBrowserModelBindercubebrowser.model.binder.js:7
    8. (anonymous function)59:478
    9. jQuery.Callbacks.firejquery-1.8.3.js:974
    10. jQuery.Callbacks.self.fireWithjquery-1.8.3.js:1084
    11. jQuery.extend.readyjquery-1.8.3.js:406
    12. DOMContentLoaded

Which looks to be caused by my 2nd view using data-bind to source and then  a template

I have tried to replicate it here: http://jsbin.com/iyayuk/7/edit and that gives me a different error but i believe it is close to the same problem.
  1. Uncaught TypeError: Cannot call method 'replace' of undefined kendo.all.min.js:9
    1. Template.compilekendo.all.min.js:9
    2. p.isFunction.fjquery-1.8.2.min.js:2
    3. parseOptionskendo.all.min.js:9
    4. (anonymous function)edit:21
    5. f

I noticed this one: http://www.kendoui.com/forums/framework/mvvm/nested-views-bindings.aspx but i dont think i can see a way to get a jquery selector to correctly exclude the deeper elements.

But beyond that I would not expect the code to throw an error.

Appreciate your help on this

Thanks

James.


2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 25 Feb 2013, 09:26 PM
Hello James,

The error in the jsBin is thrown because the templates are not yet initialized when binding the viewModel. You should bind the viewModel in the document ready event or move the script after the templates in order to avoid it.
Regarding the error with the binding - it occurs because the source binding always requires initial value. The deeper elements only cannot be excluded and you should either exclude "cubebrowserpanes" from the binding or add the "gridPane" content(or attributes) dynamically after the main viewModel is bound. I update the sample to show one possible approach.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
James
Top achievements
Rank 1
answered on 01 Mar 2013, 11:24 AM
Thanks for the response Daniel, doing the trick of putting the whole 2nd view into a template did the trick for me.
Tags
MVVM
Asked by
James
Top achievements
Rank 1
Answers by
Daniel
Telerik team
James
Top achievements
Rank 1
Share this question
or