Forum Stats

  • 3,770,440 Users
  • 2,253,113 Discussions


knockout bindings between ojModule and parent?

Jdang-Oracle Member Posts: 4
edited Dec 15, 2015 6:06PM in Oracle JET


Is it possible the container of an ojModule to interact with it via a knockout binding?

Our use case is a main page that contains navigation to a number of modules.  Each module contains one or more ojCharts.  The main page also contains time filtering UI components -- when a date range is chosen, we need to also modify the model for the charts in their respective modules.

How can this be accomplished?




  • John 'JB' Brock-Oracle
    John 'JB' Brock-Oracle Posts: 2,700 Employee
    edited Dec 15, 2015 6:06PM

    Hi James,

    Yes, you can definitely do this by setting the values that you want to share across modules to be located in the root ViewModel.  This is main.js in most of the demo's that we've written over the last year.

    You can also use observable or variables that are in the Parent ViewModel if you are doing nested modules.

    From the HTML in your different modules, you can bind the data to $root.myVariableName

    If you want to get a reference to that rootViewModel in your modules JavaScript, you can use Knockouts dataFor method.  Something like:  rootVM = ko.dataFor(document.getElementById("myElement"))

    You can read more about Knockout binding contexts at: Knockout : Binding context

    Hope that helps,