Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write data received from the server after .fetch() in model and passed to template?
    text
    copied!<p>Good day! I'm new in backbone and i writing a simple little application based backbone + jquerymobile. When I get data from the server, I need to properly transfer the data to the view, where they are passed to the template. Because the <code>.fetch()</code> asynchronous, i cant just pass in render my model. How can I do so that would after <code>.fetch()</code> data received from the server, written in the model and then passed to the template?</p> <pre><code>//template &lt;script type="text/html" class="template" id="profile-form"&gt; &lt;div data-role="header"&gt; &lt;h3&gt;Step 4&lt;/h3&gt; &lt;a href="#main" data-theme="a"&gt;Home&lt;/a&gt; &lt;a href="#logout" data-theme="a"&gt;logout&lt;/a&gt; &lt;/div&gt; &lt;div data-role="content"&gt; &lt;h2 class="ui-li-heading"&gt;&lt;%= username %&gt;&lt;/h2&gt; &lt;p class="ui-li-desc"&gt;&lt;strong&gt;&lt;%= phone %&gt;&lt;/strong&gt;&lt;/p&gt; &lt;/div&gt; &lt;/script&gt; // model var UserInfo = Backbone.Model.extend({ url: appConfig.baseURL + "users/", }); // routes profileInfo: function () { var user = new UserInfo() this.changePage(new ProfilePageView({ model: user })); }, // view var ProfilePageView = Backbone.View.extend({ initialize: function () { this.template = $.tpl['profile-form']; }, render: function (eventName) { $(that.el).html(that.template()); return this; } }); </code></pre> <p>I trying to add this part in my render in view. Its works, but my styles are not working. I'm not quite sure that I did the right thing by putting fetch in render, can advise how to do correctly?</p> <pre><code> var that = this this.model.fetch({ data: $.param({email: localStorage.getItem('user_email')}), type: 'POST', success: function (response) { $(that.el).html(that.template(JSON.parse(JSON.stringify(response)))); } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload