简体   繁体   中英

Ember Controller vs Ember ArrayController

关于何时使用Ember.Controller以及何时使用Ember.ArrayController及其用法,我没有明显区别。

With a Controller, you could do {{#each item in model}} in your template.

With ArrayController, you could simply do {{#each item}} .

Could. ArrayController is deprecated because it was obscuring the logic, you should never use it. The Controller is also being deprecated in favor of routeable components, somewhere in Ember 2.1 or 2.2.

Current strategy is the following:

  • Forget ArrayController, ObjectController and View.
  • Use components for everything.
  • Until Ember 2.1/2.2, you're unable to use a component for a root template of any route. For that template, you'll have to use a controller.
  • Don't put any logic into that controller. Simply place a component in its template and pass the model through. Use such controllers only for query params and other stuff that components are incapable of (yet).
  • In routes, don't use setupController . Instead, put everything into a model, turning it into a hash of models. RSVP.hash is your friend.
  • When routable components are available, replace controllers with components.

PS The syntax for each is changing to {{#each model as |item|}} .

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