How to access variable in javascript using flow.js?

Can I access variable in a javascript function instead of in html code? I cannot find any documentation on how to use flow.js other than html directive way.

If I use data-f-bind=“time” in html, and want to access the same variable in my section, how can I do that?

When you say “section” do you mean a JS function? There are two things you can do:

so you would do

 Flow.channel.variables.subscribe('myVariable',
     function() { console.log('called!'); } );
  • Flow triggers 2 events on the actual DOM element you can listen on: “update.f.model” and “f.convert”. For instance, say you had a domElement like <div data-f-bind="myvariable | $#,###" id="mydiv"> </div>

i.e., you take the model variable and apply a ‘formatter’ converter to it (see here or more info on converters). You can then do

$("#mydiv").on('update.f.model', function (data) {
  console.log(data); // will have the unformatted model variable
});

$("#mydiv").on('f.convert', function (data) {
  console.log(data); // will have the formatted model variable
});

Does that answer your question?

1 Like

Yes, that’s what I want to know. Thank you, Naren!