3

I'm trying to implement SPA with HotTowel Template by John Papa. Is there a limitation on how many levels of ko compose I can do?

In the shell.html it calls

<!-- ko compose: { model: router.activeItem .... } --><!-- /ko -->

Within my active view, I try to embed another view, and then I tried to embed another view and so on.

In home.html.

<!-- ko compose: { model: $data, view: view1 } --><!-- /ko -->

In view1.html, I do

<!-- ko compose: { model: $data, view: view2 } --><!-- /ko -->

In view2.html, I do

<!-- ko compose: { model: $data, view: view3 } --><!-- /ko -->

Problem is View3 is not called.

I confirmed this in the Chrome debugger trace, view3 is never called. Is there a limitation in how many levels I can go? If so how can I get around this?

Thanks in advance.

Cheers

Michael

Michael Pang
  • 366
  • 1
  • 2
  • 10
  • it just stopped to load after 3 levels ? . – phil soady Jun 05 '13 at 06:11
  • 4
    I've noticed similar issues, especially when nesting multiple Knockout containerless controls. Put your bindings in a section element and see if that clears up the issue. – chrisjsherm Jun 06 '13 at 18:33
  • Thanks. I added
    and in another instance
    in the template file and it's working now.
    – Michael Pang Jun 07 '13 at 05:18
  • 1
    Correct. It's not a direct limitation of Durandal. It's something going on with KO's containerless functionality. Can you report this issue to the KO group, providing your specifics? I can then help to put some additional "weight" behind it :) – EisenbergEffect Jun 24 '13 at 18:57
  • I should add that this is a very strange thing to do... – EisenbergEffect Jun 24 '13 at 19:06
  • Can anyone reproduce this in jsFiddle? http://jsfiddle.net/rniemeyer/vPcPL/ – RP Niemeyer Jun 24 '13 at 19:29
  • @RPNiemeyer I had some problem like this with Durandal 1.2. I found a workaround for that changes a line in knockout which is stated here as the answer: http://stackoverflow.com/questions/19751104/dynamic-composition-using-knockout-and-durandal-doesnt-work – mehrandvd Mar 04 '14 at 07:37
  • @EisenbergEffect But if you've upgraded to Durandal 2.0.1 you should rollback this change from knockout. – mehrandvd Mar 04 '14 at 07:40
  • @EisenbergEffect A slight same type of trouble I am having multiple compose in my home.html and though I am returning promise on each activate it would not run asycronous. – Anuj Pandey Sep 09 '14 at 04:57

1 Answers1

4

As you've now found out -you have to have a root element in your view (it explicitly states this in the Durandal docs):

The view has exactly one root element. Durandal requires this. If comments are found at the root, they will be removed. In the case where more than one root element is found, they will be wrapped in a div.

gerrod
  • 6,119
  • 6
  • 33
  • 45