Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8824207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:33:13+00:00 2026-06-14T06:33:13+00:00

I’m on Ember-1.0.0-pre2 and I seem to be having trouble using an {{#if}} statement

  • 0

I’m on Ember-1.0.0-pre2 and I seem to be having trouble using an {{#if}} statement around an element which has a {{bindAttr class=”…”}} and the binding conditions are the same. I.E. the if statment and class binding are to the same controller attribute. See code:

<button {{action "toggleShow" target="controller"}}>Toggle Visibility</button>
{{#if show}}
   <div {{bindAttr class="show:red:green"}}>test</div>
{{/if}}

http://jsfiddle.net/y49ch/10/

If you click the “Toggle Visibility” button several times you’ll notice you get a the common error that says: “Something you did caused a view to re-render after it rendered but before it was inserted into the DOM. Because this is avoidable and the cause of significant performance issues in applications, this behavior is deprecated …”

At first look that seems stupid, but that’s a very primitive example of my problem. In my case, there is a computed property on the end of both bindings (if and class attribute). In both cases the computed properties share a common dependent key. When that common dependent key changes it causes both helpers to be update and thus the error.

Is this a bug? I can guess what’s happening here, but it seems like I should be able to do this safely.


EDIT: The above is a primitive example of the problem I’m having. It’s meant to show it in a very simple way. Below is a more complex example.

Template:

<button {{action "toggleValue" target="controller"}}>Toggle Value</button><br>
{{#if greaterThanTen}}
  <div {{bindAttr class="isOdd:red:green"}}>test</div>
{{/if}}

Javascript:

App.myController = Ember.Controller.create({
  value: 10,

  greaterThanTen: function() {
    return this.get('value') > 10;
  }.property('value'),

  isOdd: function() {
    return this.get('value') % 2 === 1;
  }.property('value'),

  toggleValue: function() {
    this.set('value', (this.get('isOdd') ? 10 : 11));
  }
});

http://jsfiddle.net/y49ch/16/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:33:14+00:00Added an answer on June 14, 2026 at 6:33 am

    I see it now. Your original code had both points watching the same property which got me a little confused, but now it makes more sense. I can’t really get what’s going on, but I suspect it might have something to do with the runloop.

    I’ve changed your code a little (see this jsfiddle) so that div is now a child view. Some of your properties were moved from the controller to the view (does your spec allow these guys to be at the view or does it have to be at the controller? unless I missed something only the view should be concerned about isOdd and toggleValue at this point) and the css is bound through classNameBindings watching for the value property that is bound to the parent view.

    App.myController = Ember.Controller.create({
      value: 10,
    
      greaterThanTen: function() {
        return this.get('value') > 10;
      }.property('value') 
    
    });
    
    App.MyView = Ember.View.extend({
        templateName: 'my-view',
        valueBinding: 'controller.value', 
        toggleValue: function() {
            this.set('value', (this.get('isOdd') ? 10 : 11));
        },
        isOdd: function() {
             return this.get('value') % 2 === 1;
        }.property('value'),
        ChildView: Em.View.extend({
            classNameBindings: 'parentView.isOdd:red:green'        
        })
    });
    

    Now, the template looks like this:

    <script type="text/x-handlebars" data-template-name="my-view">
      <button {{action "toggleValue"}}>Toggle Value</button><br>
      {{#if greaterThanTen}}
        {{#view view.ChildView}}
           test
        {{/view}}
      {{/if}}
    </script>
    

    Since the default tag for the View is div, it renders the same html, and it totally acts as a different view and prevents unecessary re-render.

    Edit: Just as proof of concept, I’ve added a button to add to the value instead of just toggle so you can actually see the color changing after it gets visible. Here’s the fiddle

    Let me know if this is good for you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an array which has BIG numbers and small numbers in it. I
I'm trying to select an H1 element which is the second-child in its group
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.