It doesn’t look like it is possible to delay the load of a template until a response comes back from an AJAX request inside the willInsertElement property of an Ember View?
I would like to load jquery-ui.min.js before the template renders.
window.App = Ember.Application.create()
App.TestView = Ember.View.create
tagName: 'div'
template: Ember.Handlebars.compile '<div>This is a view</div>'
willInsertElement: ->
$.ajax({
url: "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"
dataType: "script"
async: false
success: (data, textStatus, jqxhr) ->
console.log data
console.log textStatus
console.log jqxhr.status
console.log "Load was performed."
});
didInsertElement: ->
console.log 'the element was inserted'
App.TestView.append()
I’m finding that the didInsertElement runs before the AJAX request is finished.
Thanks in advanced.
What do you want to achieve in the end? Assure that
jquery-uiis available before the view is inserted?successcallback then, see http://jsfiddle.net/RgcJA/$.getScriptexecuted asynchronously? Have you tried settingasync: false?