using JMVC i have this issue: this line NOT work : this.element.append('hello');
here my controller:
steal('jquery/controller',
'jquery/dom/form_params',
'jquery/view/ejs',
'jquery/controller/view')
.then(
'./home.css',
function($){
$.Controller("Wg.Home",
{
defaults : {
defaultText : "Search for things here"
}
},
{
init : function(){
this.render();
},
render : function(){
$("body").addClass("home");
this.rendered = true;
this.element.html(this.view(this.options));
this.element.append("<div>Hi there</div>");
}, ...
i need to manipulate the EJS html after view render but i can’t. what i miss?
Thanks
MORE INFO:
I run my controller from router.js in this way:
this.home = new Wg.Home(this.container);
this.container is :
this.container = $('#page');
and my init.ejs is:
<div class="form-container">
<form action="" method="get" class="form-wrapper clearfix">
<input type='text' placeholder="<%=defaultText%>" name='q' id="q" class='blurred'/>
<button type="submit">Search</button>
</form>
</div>
I have no error.
Based on the comments below I think to have understood your kind of issue. You’re invoking the view in this way:
You need to look at this statement ˋWg.Models.Artists.findAll()ˋ. This is nothing else than a wrapper around a jQuery ajax call which is asynchronous. JavaScriptMVC added support for directly handling async ajax calls in the ˋthis.viewˋ method which is done through jQuery Deferreds. That means when you invoke the above instruction, what happens is
The problem however is that ˋthis.element.append(…)’ is done before the ajax call returns, basically your ˋinitˋ view is rendered after your ˋthis.element.append(…)ˋ happens.
What you could try is to do the following:
Try if that works for you.
//Edit:
This article from the docs might be quite helpful: