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

  • Home
  • SEARCH
  • 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 7912413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:35:37+00:00 2026-06-03T13:35:37+00:00

I have a view that is instantiated in an {{#each}} block, so there are

  • 0

I have a view that is instantiated in an {{#each}} block, so there are multiple instances. Each view needs to have a bound property to an object that is specific to that view instance. So the usual way of declaring a binding:

App.hash = Ember.Object.create({
   item1: "one",
   item2: "two"
});
App.MyView = Ember.View.extend({
   itemBinding: "App.hash.itemN"
});

won’t work because When I define what the binding maps to (App.hash.itemN) I don’t know yet whether it should be item1 or item2 (represented in the above code by itemN).

I have found a way around this, that seems a bit kludgey, and am curious if there’s a proper way. Here is my solution:

App.MyView = Ember.View.extend({
   didInsertElement: function() {
      this.set('stub', Ember.Object.create({
        itemBinding: "App.hash."+this.get('content')}))
   }
})

Then in my template I can do the following:

{{#each App.itemController}}
   {{#view App.MyView contentBinding="this"}}
      {{stub.item}}
   {{/view}}
{{/each}}

Is there a better way to do this? My complaints are that I feel like I’m creating an unnecessary object. Also, if I want other properties of my view to depend on this instance-specific object, I can say .property(stub.item) which happens to work, despite that when it’s declared, stub.item doesn’t exist yet.

I thought there might be some way involving manually creating a binding, but I couldn’t figure that out.

Thanks!

Update:

I’ve confirmed that Christopher Swasey’s solution works. I’ve fleshed it out in this Gist:

https://gist.github.com/2606979

This was very helpful, as I learned more about observes and callbacks. Although in the end, I’m not sure how much simpler this solution is. Nonetheless, it works at least as well.

  • 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-03T13:35:38+00:00Added an answer on June 3, 2026 at 1:35 pm

    You can make stub a computed property:

    hashBinding: 'App.hash',
    stub: function() {
        return this.get('hash').get(this.get('content'))
    }.property('hash', 'content').cacheable()
    

    Updated:

    contentWillChange: function() {
        this.removeObserver('hash.' + this.get('content'), this, 'stubDidChange');
    }.observesBefore('content'),
    
    contentDidChange: function() {
        this.addObserver('hash.' + this.get('content'), this, 'stubDidChange');
        this.stubDidChange();
    }.observes('content'),
    
    stubDidChange: function() {
        this.notifyPropertyChange('stub');
    },
    
    stub: function() {
        return this.get('hash').get(this.get('content'))
    }.property().cacheable()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view called DashboardView that instantiates multiple WidgetView s. Each widget needs
I have a view that shows user profile fields in a tabular format. There
I have an iphone app that uses table view as the interface. Each time
I have two classes that each need an instance of each other to function.
I am beginner in rails. I have view that i try to print inside
I have a view that has a column to make it sortable. When clicking
I have a view that renders a list elements using the following template :
I have a view that is used in a UINavigationController and and is automatically
I have a View that is basically setup like this: <Grid> <ViewBox> <Grid> <ItemsControl
I have a View that contains a ParentModel, which contains 2 Models. I only

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.