我必须为每个Ember.js应用程序明确创建一个“ApplicationView”和“ApplicationController”? [英] Do I have to explicitly create an `ApplicationView` and an `ApplicationController` for every Ember.js application?

查看:121
本文介绍了我必须为每个Ember.js应用程序明确创建一个“ApplicationView”和“ApplicationController”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Trek's tutorial:


您的应用程序必须具有ApplicationView属性。将为您创建
的一个实例,并将其作为根视图插入到应用程序的
视图层次结构中。


本教程提供了此示例代码:

  App.ApplicationView = Ember.View.extend({
templateName:'application'
});

App.ApplicationController = Ember.Controller.extend();

有关 ApplicationView ApplicationController中?他们的特定名称是否保留,必须通过转换使用或有什么特别的路由器引用它们的方式?



据我了解,Ember的一个原则是消除样板代码。所以我猜想有更多的是为每个应用程序明确地创建这两个视图作为起点 - 否则,Ember只是让它在场景后面。



要重新表达我的问题,什么使 ApplicationView ApplicationController 特别在Ember应用程序。我需要为每个应用程序明确创建它们,如果是这样,我需要按照惯例命名吗?



注意:我正在使用ember-latest >

解决方案

Ember.js试图坚持约定超过配置的编程理念。因为这一些事情需要具体命名,并遵循正确的套管规则。在调用 App.initialize()时,您的应用程序将自己查找属性 App.ApplicationView 。然后,您的应用程序呈现此视图,将其插入到dom中,并自动创建一个 App.ApplicationController 的实例,将其设置为的渲染上下文ApplicationView 。这意味着您的 ApplictationController 中的任何属性只需在视图中引用它们即可绑定到您的 ApplicationView 中。 p>

如果您使用 App.ApplicationView App.initialize() $ c>或 App.ApplicationController ember会抛出一个错误,让你知道你必须创建它们。



ApplicationView ApplicationController 是您的ember应用程序的组成部分,必须存在。 Ember是一个MVC框架, ApplicationView 是您的根V, ApplicationController 是您的根C.可以尝试尝试要使用像Ember这样的框架,只需要你想要的东西,但是只要多一点工作,你会有一个更强大,易于使用的应用程序,试图挑选功能。


From Trek's tutorial:

Your application must have an ApplicationView property. An instance of this class will be created for you and inserted into the application's view hierarchy as the root view.

And the tutorial gives this example code:

App.ApplicationView = Ember.View.extend({
  templateName: 'application'
});

App.ApplicationController = Ember.Controller.extend();

What is special about ApplicationView and ApplicationController? Is their particular name reserved and must be used by conversion or is there something special about the way the router refers to them?

As I understand it, one of Ember's principals is to eliminate boilerplate code. So I am guessing there is something more to explicitly creating these two views for every app as starting point -- otherwise Ember would just make them for me behind the scene.

To rephrase my question, what makes ApplicationView and ApplicationController special in an Ember application. Do I need to create them explicitly for every app and if so, do I need to name them following a convention?

Note: I am using ember-latest

解决方案

Ember.js tries to adhere to the programming philosophy of convention over configuration. Because of this some things need to be specifically named and follow correct casing rules. Upon calling App.initialize() your application looks for the property on itself App.ApplicationView. Your app then renders this view, inserts it into the dom and auto-creates an instance of App.ApplicationController, setting it as the render context for your ApplicationView. This means that any properties in your ApplictationController can be bound in your ApplicationView simply by referencing them in the view.

If you call App.initialize() with out an App.ApplicationView or App.ApplicationController ember will throw an error letting you know you must create them.

ApplicationView and ApplicationController are integral parts of your ember application and must exist. Ember is an MVC framework, ApplicationView is your root V, ApplicationController is your root C. It can be tempting to try to use frameworks like ember for just the pieces that you want, but with just a little more work you'll have a much more robust, and easy to use application that trying to cherry pick functionality.

这篇关于我必须为每个Ember.js应用程序明确创建一个“ApplicationView”和“ApplicationController”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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