easy access to component models in nested components

75 views
Skip to first unread message

Noirabys

unread,
Feb 8, 2018, 2:22:29 AM2/8/18
to KnockoutJS
hi, 
is there a nice/easy way to access parent component models ?
if components are nested on multiple levels it becomes dirty very quick.
I think there is missing an "as" feature to give component models speaking names.

<my-businessmodel params="{}">
   <my-panel params="{}">
      //  access values of businesscomponent here
     // my-panel is also a component, thus access would be something ugly like:
    // $parentContext.$component....
   </my-panel>
</my-businessmodel>

as a workaround i found following, which is either not nice but makes the code more readable/maintainable:

<my-businessmodel params="{}">
    <!-- next line is the workarond: -->
    <!-- ko foreach: { data: [$component], as: 'myBusinessmodel'} -->

   <my-panel params="{}">
        // now we can access parentModel via the given name myBusinessmodel 
        <div data-bind="text: ko.toJSON(  myBusinessmodel ) "></div>

   </my-panel>

    <!-- /ko -->
</my-businesscomponent>

anyone has a better solution for this ?

one idea might be a custom binding to expose component models , for example export which exports the component model  ?
<my-businessmodel params="{}" data-bind="export: 'myBusinessmodel">


best regards,
  noirabys

Noirabys

unread,
Feb 19, 2018, 3:16:04 AM2/19/18
to KnockoutJS
hi,
is there no solution, or is the question not understandable ?

best regards,
 noirabys

Michael Best

unread,
Feb 27, 2018, 2:02:29 PM2/27/18
to KnockoutJS

Noirabys

unread,
Mar 1, 2018, 4:25:17 AM3/1/18
to KnockoutJS
thanks Michael,
 that is looking good!

would be great to have some simple examples of the new features.

best regards,
 noirabys
Reply all
Reply to author
Forward
0 new messages