Wednesday 15 January 2014

ember.js - Model.find().then() fires before records are actually loaded -


I would like to load an entire collection and then peel the record to use it as a no-model Every roundtrip on the server.

I have come to know how to use amber. Different to a promise back, but I can not find the promise to solve at the right time. The following code will only "get 0" at any time:

  App.PersonRoute = Ember.Route.extend ({Model: Function (parameter) {var name = "Eric"; var promise = Ember Deferred.create (); App.people = App.Person.find (); App.people.then (function () {console.log ('found' + App.people.get ('length')) Var person = App.people.findProperty ('name', name) promise.resolve (person);}); return promise;}});   

If I wrap the body of () in a set timeout, and wait for it a few seconds, then everything works great.

Is there any other event binding in some way? I tried the app. Region. But ('low load'), but loading is always true.

Thank you!

Is there any other event that I can somehow bind?

There is actually an incident that you can hear and it is didLoad .

I tried the app. People are 'isloaded', but theloaded is always true. There is so much confusion about isLoaded as

, for example, confusion comes from the fact that isloaded flag is correct Is set to by design when the store is finished RecordArray is being loaded for records, even if initially empty because any record Already available locally, then when the request for the server returns, then the RecordArray with Records received from the backend Will be populated, and the binding will stop and your templates will be updated.

As stated:

A record that is both full and clear, which has received information about its features and relationships with the server, and the client But no change has been done locally.

As mentioned above, which creates didLoad fire.

You can see the guide for more models related events >

Now in your setup, you can write your code like this: < Pre> App.PersonRoute = Ember.Route.extend ({Model: Functions (Parameters) {var name = "Eric"; Y promise = Amber. Answers.Create (); App people = app.pson.fund (); App.pogol.on ('delload', function () {console.log ('found' app .people.get ('length')); var person = App.people.findProperty ('name', Name) promise.resol (person);}); return promise;}});

Hope it helps.

No comments:

Post a Comment