Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to pass variables between modules

user1950921Feb 10 2016 — edited Feb 12 2016

I want to know how to initialise variables that are being used in other modules.

In this Hands-On-Lab (Oracle JET - Hands-On-Lab ) you must initialise the variable val with this statement: self.val = ko.observableArray(['bar']);

After this I used this example Oracle JET - Router - ojModule with nested routers from the cookbook to build a single page application.

In this single page application I build the HOL example and a chart. My issue is now that I can't initialise the variable for the select.

In main.js this is the document.ready function with the applyBindings:

$(document).ready(function() {

      oj.Router.sync().then(function() {

         ko.applyBindings(viewModel, document.getElementById('routing-container'));

      });

   });  

In the chart.tmpl.tmpl this is the part of the select:

        <select id="basicSelect"

                    data-bind="ojComponent: {component:'ojSelect',                                                   

                    value: val,                                                   

                    rootAttributes: {style:'max-width:20em'}}">

                <option value="line">Line</option>

                <option value="bar">Bar</option>

                <option value="area">Area</option>

                <option value="combo">Combination</option>

                <option value="lineWithArea">Line with Area</option>

            </select>

In the chart.js I use the following code to process the data:

   var viewModel = {

        router: undefined,

        initialize : function(data) {

            if (this.router) {

                return;

            }

        router = oj.Router.rootInstance;

        oj.Router.sync();  

        },

        selectHandler: function(event, ui) {

         if ('chart-container' === event.target.id && event.originalEvent) {

            viewModel.router.go(ui.key);

         }

         }

   };

How can I set the initial value of the ojselect from the main.js?

Comments
Post Details
Added on Feb 10 2016
3 comments
11,988 views