You need to sign in to do that
Don't have an account?
Peter Friberg 26
How to create reusable methods in Lightning JS client side controller for reuse within the client side controller itself
Normally when creating Javascript methods in Visualforce they exist in the same scope, e.g. you can call one method from another with parameters. Just as the two functions findNext() and findPrev() calls findAndFocus() here:
What if the helper file methods need to call other methods within the same helper Javascript file?
Any thoughts or ideas?
function findPrev() { search_index--; findAndFocus(text, search_index); } function findNext() { search_index++; findAndFocus(text, search_index); } function findAndFocus(str, stop_at) { // Do something }But when using Lightning how do you call one method from another?
({ findPrev : function (component, event, helper) { search_index--; findAndFocus(text, search_index); // What to write here? }, findNext : function (component, event, helper) { search_index++; findAndFocus(text, search_index); // What to write here? }, findAndFocus : function(text, stop_at) { // Do something } })What is the best practice? Is it to move all methods for reuse into the helper client side Javascript file?
What if the helper file methods need to call other methods within the same helper Javascript file?
Any thoughts or ideas?
Kindly mark this as a solution, if you find it useful.
All Answers
Kindly mark this as a solution, if you find it useful.
I was close but was missing the this keyword :)
/Peter
The function "addItem" works well when the action is called by a button, but not on a "init" function for example (in this case, "this" is undefined)
https://salesforceblog.tumblr.com/post/178881975383/how-to-call-lightning-component-js-controller-call