有人可以分解公约与emberjs的配置方面吗? [英] Can someone break down the conventions vs. configuration aspects of emberjs?

查看:74
本文介绍了有人可以分解公约与emberjs的配置方面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了MVC的概念方面,以及它们是如何实现的。在emberjs中,公约方法是有道理的,看起来很简单。但是,您如何决定何时使用objectcontroller与indexedcontroller等,以及如何学习或保留约定,以便您可以快速进行逻辑编程设计决策,以决定您采用哪种方向或方法?

我的意思是你如何将这样的分钟公约作为逻辑思维?


如果你不要为post路由
(App.PostRoute)指定路由处理程序,Ember.js仍然会使用
应用程序的App.PostController实例来呈现Post模板。



如果不指定控制器(App.PostController),Ember将
根据
路由的模型钩子的返回值自动为您创建一个。如果模型是一个数组,你会得到一个
的ArrayController。否则,你得到一个ObjectController。



如果没有指定一个帖子模板,Ember.js将不会呈现任何东西!


http://emberjs.com/guides/concepts/naming-conventions/#toc_route-controller-and-template-defaults



另外,相应地有没有关于视图与组件与属性的约定,以及这些方法是如何从围绕路由,路由器,控制器的约定中排除的?



谢谢 -



David

解决方案

控制器是真正的装饰器。它们将控制器的属性代理到其下的模型。因此,有三种不同类型的控制器。 ArrayController ObjectController 控制器



ArrayController 由集合支持



ObjectController 由单个对象支持



控制器没有任何对象支持它



真的是诀窍是开始小。单一模板,单路,单控制器。不要尝试添加任何东西,直到遇到问题,你不知道如何解决。



示例: http:// emberjs。 jsbin.com/sohijunu/1/edit



一旦获得了一条路线的要点,单控制器,单个模板,就可以开始尝试多个路线等。这很像大学,实验的时间,但你开始小。



示例: http:// emberjs。 jsbin.com/OxIDiVU/726/edit


I get the conceptual aspects of MVC and how they are generally implemented. In emberjs the conventions approach makes sense and is seemingly straightforward. But, how do you decide when to use an objectcontroller vs. an indexedcontroller and such, and how is one to learn or retain the conventions so you can make quick logical programmatic design decisions as to which direction or approach you take?

I mean how do you commit such minute conventions like these into logical thinking?

If you don't specify a route handler for the post route (App.PostRoute), Ember.js will still render the post template with the app's instance of App.PostController.

If you don't specify the controller (App.PostController), Ember will automatically make one for you based on the return value of the route's model hook. If the model is an Array, you get an ArrayController. Otherwise, you get an ObjectController.

If you don't specify a post template, Ember.js won't render anything!

http://emberjs.com/guides/concepts/naming-conventions/#toc_route-controller-and-template-defaults

Also, correspondingly are there conventions around views vs. a component vs. a property and how those all funnel out from the conventions around routing, routers, controllers?

thanks -

David

解决方案

Controller's are really decorators. They proxy properties from the controller to the model beneath it. As such there are three different types of controllers. ArrayController, ObjectController, and Controller.

ArrayController is backed by a collection

ObjectController is backed by a single object

Controller doesn't have any object backing it

Really the trick is to start small. Do a single template, single route, single controller. Don't attempt to add anything else until you run into a problem you don't know how to solve.

Example: http://emberjs.jsbin.com/sohijunu/1/edit

Once you get the gist of a single route, single controller, single template, you can start experimenting with multiple routes etc. It's a lot like college, a time of experimentation, but you start small.

Example: http://emberjs.jsbin.com/OxIDiVU/726/edit

这篇关于有人可以分解公约与emberjs的配置方面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆