[wp-trac] [WordPress Trac] #30505: Backbone subviews cannot be attached directly to DOM elements

WordPress Trac noreply at wordpress.org
Fri Sep 30 15:50:45 UTC 2016


#30505: Backbone subviews cannot be attached directly to DOM elements
----------------------------+------------------------------
 Reporter:  rmccue          |       Owner:
     Type:  defect (bug)    |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Administration  |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  needs-patch     |     Focuses:  javascript
----------------------------+------------------------------

Comment (by nerrad):

 So I ran into this while working on a project so just thought I'd post
 what I'm finding so far here.  Basically my use case is I've got an
 already loaded wp list table.  I have a main parent view that is the list
 table tbody element.  And then I want each existing row in the table to be
 its own subview.  For this initial implementation backbone along with the
 wp-api client js library is just being used to do quick edit like tasks in
 the rows.  The initial models data in the subview isn't fetched until an
 event is fired in the row.

 Anyways, where I ran into issues is exactly as Ryan first described in
 here where I couldn't add the `tr` selectors as subviews in the parent
 view via a loop.  I then tried what Adam suggested (leaving the selector
 blank on creating the subview) and then added my row element as a selector
 in the el property for the subview and so far that seems to be working.
 Something like this:

 {{{
 //setup all rows as their own
 this.$el.find( 'tr' ).each( function() {
      var row = $(this);
      self.views.add( new ev.SourceView( { el: row, model:new
 wp.api.models.Source( {id: 0} ) } ) )
 });
 }}}

 I'm really new to backbone so still learning as I go, so you can reuse the
 disclaimer @georgestephanis gave here as well :)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30505#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list