Is it possible to create a Handlebars Helper Function that returns async result? Maybe Handlebars supports some kind of two way binding? I want to use JSON data from JSONP request so jQuery.ajax also does not support async: false, but however this would not be exactly the same that I am looking for.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
You can call whatever functions you want in a helper but that won't do you any good. The problem is that Handlebars helpers work with strings and someone else will convert those strings to DOM elements. But, by the time your AJAX call finishes, there won't be any useful connection between the DOM elements that were built based on the string that Handlebars produced and any context that you can capture in a success callback inside a helper.
I think the best you can do is break it into two pieces:
class
anddata-*
attributes for the structure.class
anddata-*
attributes from 1, launch the appropriate AJAX calls, and then patch up the DOM in the success handlers.Maybe not that helpful but that's probably the best you can do when working with a text-based template system.