How to push my Records into SC.ArrayController content?

163 Views Asked by At

I am trying to get my sample data (records created from fixtures) into my SC.ListView. I know the records are built properly because I am able to get particular data by finding it by its primaryKey.

The SC.ListView is pulling its content via contentBinding: 'MyApp.thisController.arrangedObjects' from this SC.ArrayController:

MyApp.thisController = SC.ArrayController.create(SC.SelectionSupport, {
    allowsMultipleSelection: NO,
    content: MyApp.store.find(MyApp.MyRecordType)
});

To init the store I use the function from the official guide:

store: SC.Store.create().from(SC.Record.fixtures)

How do I set my content property in the controller right to import the SC.RecordArray?

2

There are 2 best solutions below

1
On BEST ANSWER

this will only work if your store is created before your controller. Try doing

MyApp.thisController.set('content', MyApp.store.find(....));

after the app loads, in the console. If that works, you need to query the store after your app initializes.

0
On

my problem was that the store was generated AFTER the controller tried to set the content, which is very confusing because with the following code from another tutorial it is working fine.

store: SC.Store.create().from(SC.FixturesDataSource.create({
    simulateRemoteResponse: YES,
    latency: 250
}))

Anyone knows to tell me why the store creation in the question text fails to generate before?