Note that there are some explanatory texts on larger screens.

plurals
  1. POSibling attribute binding in Ember.js
    primarykey
    data
    text
    <p>I am a relative Ember newbie, so I may be missing something obvious here. I'm trying to build a custom view for a Bootstrap accordion. I'm using relative views for this, and while it is working, I'd like to understand if I can simplify a little bit. Specifically, I'd like to know if it's possible to make the <code>href</code> computed property of the embedded <code>toggleView</code> dependent on the <code>elementId</code> of the embedded <code>bodyView.</code> Here's the top level view, which is a collection:</p> <pre><code>App.AccordionView = Em.CollectionView.extend({ headingTemplateName: 'accordion-heading', innerTemplateName: 'accordion-inner', tagName: 'div', classNames: ['accordion'], contentBinding: 'controller.content', </code></pre> <p>The item view corresponds to the DOM element with the <code>accordion-group</code> css class.</p> <pre><code> itemViewClass: Em.View.extend({ tagName: 'div', classNames: ['accordion-group'], target: null, template: Em.Handlebars.compile("{{view view.headingView contentBinding='view.content'}}{{view view.bodyView viewName='bodyViewInstance' contentBinding='view.content'}}"), headingView: Em.View.extend({ tagName: 'div', template: Em.Handlebars.compile("{{view view.toggleView contentBinding='view.content'}}"), classNames: ['accordion-heading'], toggleView: Em.View.extend({ tagName: 'div', // Can be an 'a' templateNameBinding: 'parentView.parentView.parentView.headingTemplateName', classNames: ['accordion-toggle'], attributeBindings: ['dataToggle:data-toggle', 'dataParent:data-parent', 'href'], dataToggle: 'collapse', dataParent: function() { return this.get('parentView.parentView.parentView.elementId'); }.property(), </code></pre> <p>Note that I've made the <code>href</code> property dependent on the <code>target</code> field in the item view.</p> <pre><code> href: function() { return "#" + this.get('parentView.parentView.target'); }.property('parentView.parentView.target') }) }), bodyView: Em.View.extend({ tagName: 'div', template: Em.Handlebars.compile("{{view view.innerView contentBinding='view.content'}}"), classNames: ['accordion-body', 'collapse'], </code></pre> <p>This field is set when the <code>bodyView</code> embedded view instance is inserted into the DOM.</p> <pre><code> didInsertElement: function() { this.get('parentView').set('target', this.get('elementId')); }, innerView: Em.View.extend({ tagName: 'div', classNames: ['accordion-inner'], templateNameBinding: "parentView.parentView.parentView.innerTemplateName" }) }) }) }); </code></pre> <p>That all works. However, I'd like to do something like this in the <code>toggleView</code>:</p> <pre><code>href: function() { return "#" + this.get('parentView.parentView.bodyViewInstance.elementId'); }.property('parentView.parentView.bodyViewInstance.elementId') </code></pre> <p>When I do, I get the following error, and I'm not sure I understand why:</p> <pre><code>Error: Something you did caused a view to re-render after it rendered but before it was inserted into the DOM. </code></pre> <p>Is there any way to accomplish what I'm looking to do?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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. 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