简体   繁体   中英

How to push my Records into SC.ArrayController content?

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 ?

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM