简体   繁体   中英

Render immediately in Ember.js

I have a route where model method returns a promise. According to Ember.js spec , this results in certain operations (rendering, setupController ) being delayed until the promise is resolved.

This is no good in my case. I would like the view to render immediately. Then, once the model becomes available, I would like to set a property on the controller. This would result in re-rendering of the appropriate parts of the view.

What would be the correct way of doing this? In particular I don't want to operate on promises inside my controller. Ideally I would have all the dependency setup done inside a route, just as is the case now.

Solved it using LoadingRoute , example here:

http://jsfiddle.net/u3w9Q/

Note that newer versions (>= 1.3 I think) also support more sophisticated scenarios. More details here:

http://emberjs.com/guides/routing/loading-and-error-substates/

Had a similar issue. I got around the immediate issue of rendering by waiting for the didInsertElement to fire on the View and then called an action on the controller by using this.get('controller').send('actionInsideControllerHere'); . That action calls one of my models (objects) and also changes a property on the controller to show "spinners" over components which were waiting for data. There might be a better way to do this, but that is what I came up with for now. Let me know if that works for ya.

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