This must have been asked before, I am just not sure exactly what to search for, I can delete the question if someone links to a duplicate! Thanks.
If I have a javascript function which calls an external api, how can I pass other parameters before the data is returned? Eg using Google Apps, the tasks api returns a list of the user's tasks like so:
google.script.run
.withSuccessHandler(showTasks) // showTasks callback function
.getTasks(taskListId);
}
/* Show the returned tasks on the page. */
function showTasks(tasks) {
// tasks is now an object of tasks returned by google
...
However, I want to do this:
var tasksListNumber = 1;
google.script.run
.withSuccessHandler(showTasks(null, tasksListNumber)) // showTasks callback function
.getTasks(taskListId);
}
/* Show the returned tasks on the page. */
function showTasks(tasks, tasksListNumber) {
// tasks is now an object of tasks returned by google
// tasksListNumber is 1
...
Does the solution involve using the bind function somehow?
Not used Google Aps api. But reading there docs -> The server's return value is passed to the function as the first argument, and the user object (if any) is passed as a second argument.
So to me, something like ->
google.script.run .withUserObject(tasksListNumber) .withSuccessHandler(showTasks) // showTasks callback function .getTasks(taskListId); }
In your code your basically executing showTasks(null, tasksListNumber)
instantly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.