1

I have 6 'page' objects held in an 'pages' ArrayProxy object.

I have a StateManager instance that will regulate the 6 views corresponding to these 6 'page' objects.

App.stateManager = Ember.StateManager.create({
  rootElement: '.tab-content',
  initialState: 'firstTab',
  firstTab: Ember.ViewState.create({
    view: Ember.View.extend({
      templateName: 'first',
      contentBinding: 'App.tempObject'// binding to a regular Ember Object works.
    })
  }),
  secondTab: Ember.ViewState.create({
    view: Ember.View.extend({
      templateName: 'second',
      contentBinding: 'WHAT GOES HERE?'//how to bind to an object in an array
    })
  })

The problem is that it is not clear how to bind a view to a particular object in an ArrayController.

I have a jsFiddle illustrating the problem here: http://jsfiddle.net/lifeinafolder/xUNUN/

For illustration purposes, the jsFiddle only has 2 states instead of all 6.

A similar problem is shown here: Ember.js binding models stored within an array. The solution is not very clear though.

1 Answer 1

1

You could create a computed property which returns an object at specific index, see http://jsfiddle.net/pangratz666/MUUs3/:

App.ObjectAtBindable = Ember.Mixin.create({
    targetObject: function() {
        var objectIndex = this.get('objectIndex');
        var controller = this.get('controller');
        if (controller) {
            return controller.objectAt(objectIndex);
        }
        return null;
    }.property('controller', 'objectIndex').cacheable()
});

App.stateManager = Ember.StateManager.create({
    firstTab: Ember.ViewState.create({
        view: Ember.View.extend(App.ObjectAtBindable, {
            templateName: 'first',
            contentBinding: 'targetObject',
            controllerBinding: 'App.controller',
            objectIndex: 0
        })
    })
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.