Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From what I understand, <code>$.mobile.loadPage()</code> grabs the desired html and attaches it to the DOM.</p> <p>Currently, you're trying to set <code>el</code> after the <code>View</code> has been instantiated.</p> <p>However, notice that Backbone.View attaches <code>el</code> and <code>$el</code> <a href="http://backbonejs.org/docs/backbone.html#section-117" rel="nofollow">when it's instantiated</a>:</p> <pre><code>var View = Backbone.View = function(options) { ... this._ensureElement(); this.initialize.apply(this, arguments); this.delegateEvents(); }; </code></pre> <p>Also notice that <a href="http://backbonejs.org/docs/backbone.html#section-126" rel="nofollow"><code>View.setElement()</code></a> sets <code>$el</code> by passing a selector or a jQuery objected to <code>View.el</code>:</p> <pre><code>setElement: function(element, delegate) { if (this.$el) this.undelegateEvents(); this.$el = element instanceof Backbone.$ ? element : Backbone.$(element); this.el = this.$el[0]; if (delegate !== false) this.delegateEvents(); return this; } </code></pre> <h2>Bottom line:</h2> <p>You need to set <code>el</code> (in your case with the provided jQuery object) while instantiating it:</p> <pre><code>// Where `view` is a reference to the constructor, not an instantiated object var loadPage = function(url, view) { $.mobile.loadPage(url, true).done(function (absUrul, options, page) { var v, pageId = page.attr('id'); v = new view({ el: page }); ... } } </code></pre> <p>You now call <code>loadPage()</code> like so:</p> <pre><code>loadPage('login.html', LoginView); </code></pre> <p>This gives <code>Backbone.View</code> the <code>$el</code> which to delegate your events.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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