Here is my render() function:
initialize: function() {
this.selectDivView = new SelectView({
url: '/ir/secure/api/v40/myvariants/myVariantDBs',
method: 'POST',
template: myVariantDBFilterTemplate
});
},
render: function() {
this.$el.html(template()); //has div for "select drop down"
this.selectDivView.setElement(this.$(this._selectDivId)).render();
this.afterRender();
},
afterRender: function() {
this.$(this._selectEl).val();
//Expected to get some value but the select control is not yet rendered in dom
}
I tried doing it in the way mentioned at this link Backbone.js event after view.render() is finished but was not able to access DOM elements.
Here is my Select control's handlebar template selectDiv.html
{{#each filters}}
<option value="{{id}}">{{name}}</option>
{{/each}}
I guess the DOM is not refreshed by the time I am in afterRender(). What can be done here ?
My render function of SelectDivView
render: function(selectedValue) {
this.selectedValue = selectedValue;
$.ajax({
url: this.url,
method: this.method,
async: false, // THIS IS THE DECIDING PROPERTY.
success: function(data) {
that.filters = data;
that._doRender.call(that);
}
});
}