Knockout ViewLocator

44 views
Skip to first unread message

Anargyros Tomaras

unread,
May 4, 2016, 4:24:04 PM5/4/16
to KnockoutJS
Does KnockoutJS provide some way to implement a ViewLocator?

A ViewLocator is similar to a component binding but the difference is that it binds to a ViewModel object and
automatically figures out the correct View to instantiate and bind.

For example i want to write this

<div data-bind="'component: DetailsViewModel"></div>

and i want to find and create the DetailsView.html and bind it to the data bound DetailsViewModel observable.


Is this possible?

Gunnar Liljas

unread,
May 4, 2016, 6:18:19 PM5/4/16
to knock...@googlegroups.com
How is DetailsViewModel loaded?

Somehow, the viewlocator needs to know where the viewmodel is located, so that can it resolve a path (or module id) for the view.


/G 

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anargyros Tomaras

unread,
May 4, 2016, 10:53:18 PM5/4/16
to KnockoutJS
To be more exact heres the code

<div data-bind="'component: $data"></div>

where the $data is the DetailsViewModel.

So the binding handler knows the ViewModel object. What i want is to write logic
to resolve the View based on my own naming convention.

I do not want to have to specify a component name inside the data-bind and
also i do not want to have to register every View/ViewModel pair.

Peter Shaw

unread,
May 19, 2016, 2:36:00 PM5/19/16
to KnockoutJS
These 2 links in the knockout documentation should give you all you need.

Essentially, you need to implement a custom loader.



Shawty
Reply all
Reply to author
Forward
0 new messages