0

The following link works till for positions but when i add another object(company) it is not displaying anything.

Refer the fiddle

App.jsonObject = {
    id: 1812,
    name: 'Brokerage Account',
    positions: [
        {
            symbol: 'AAPL',
            quantity: '300',
            company:[
                {
                    no: '1',
                    name: 'test'
                }
                ]
        },
        {
            symbol: 'GOOG',
            quantity: '500',
            company:[
                {
                    no: '2',
                    name: 'test123'
                }
                ]
        }
    ]
};
0

1 Answer 1

2

The reason why this is not working is because down your JSON structure you have plain javascript objects. For ember to be aware of changes and bindings to work you always need to use the framework's methods like Ember.Object.create (like you already do with App.account), objectAt(0), pushObject() etc. to create your data structure. This way your bindings and everything else will then work as expected.

Edit in response to your last comment

A simplistic very straight forward way would be to change your code to this:

App.account = Ember.Object.create({
  id: 1812,
  name: 'Brokerage Account',
  positions: Ember.A([
    Ember.Object.create({
      symbol: 'AAPL',
      quantity: '300',
      company: Ember.A([
        Ember.Object.create({
          no: '1',
          name: 'test'
        })
      ])
    }),
    Ember.Object.create({
      symbol: 'GOOG',
      quantity: '500',
      company: Ember.A([
        Ember.Object.create({
          no: '2',
          name: 'test123'
        })
      ])
    })
  ])
});

So you can later use framework methods and do stuff like:

App.get('account').get('positions').pushObject(Ember.Object.create({symbol: 'MSFT', quantity: 200}));

or

App.get('account').get('positions').objectAt(0).setProperties({'quantity': 500});

and here your updated fiddle: http://jsfiddle.net/WkGkj/3/

Note, the fiddle is now working but please don't quote me on this approach since it's not the preferred ember way of building ember applications, I just made it work to backup my answer :) Also worth mentioning is that in your fiddle you are using 'ember 0.9.4which is now very outdated since version1.0.0-rc.6.1` is around.

Hope it helps.

Sign up to request clarification or add additional context in comments.

5 Comments

please can you help in this topic
@RelicSet, let's finish one topic first :) is my answer working for you?
Already I am having a ember application with rails and it is large size application. So i need to complete most of my work in rails else browser will crash. This is working fine but i dont think this is good one.
@RelicSet, but it answers this question or not? if it does you should accept it first :)
can you help me in this topic

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.