Skip to content

Commit

Permalink
Merge branch 'master' of github.com:emberjs-cn/www.emberjs.cn
Browse files Browse the repository at this point in the history
Conflicts:
	source/bilingual_guides/getting-started/adding-a-route-and-template.md
	source/guides/getting-started/adding-a-route-and-template.md
  • Loading branch information
towerhe committed Nov 28, 2014
2 parents cec5393 + 50729fd commit 4b30f9c
Show file tree
Hide file tree
Showing 47 changed files with 504 additions and 484 deletions.
2 changes: 1 addition & 1 deletion source/bilingual_guides/application/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Most people call their application `App`, but you can call it whatever
makes the most sense to you. Just make sure it starts with a capital
letter.

大部分人都选择将他们的应用命名为`App`但是你可以将其命名为任何其他多余你来说更有意义的名字,只需要保证名称的首字母大写即可。
大部分人都选择将他们的应用命名为`App`但是你可以将其命名为任何其他对于你来说更有意义的名字,只需要保证名称的首字母大写即可。

What does creating an `Ember.Application` instance get you?

Expand Down
43 changes: 25 additions & 18 deletions source/bilingual_guides/getting-started/accepting-edits.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ Create a new file `js/views/edit_todo_view.js`. You may place this file anywhere

首先我们需要创建一个新的文件`js/views/edit_todo_view.js`。你可以将该文件放置到任意你喜欢的地方(即使将所有代码放置在同一个文件中),不过本指南将假设你按照指定的方式创建和命名该文件。

In `js/views/edit_todo_view.js` create an extension of `Ember.TextField`:
In `js/views/edit_todo_view.js` create an extension of `Ember.TextField` and register it as
a [helper](/api/classes/Ember.Handlebars.html#method_helper):

`js/views/edit_todo_view.js`中创建一个`Ember.TextField`的扩展
`js/views/edit_todo_view.js`中创建一个`Ember.TextField`的扩展并注册成为一个[助手](/api/classes/Ember.Handlebars.html#method_helper)

```javascript
Todos.EditTodoView = Ember.TextField.extend({
didInsertElement: function () {
didInsertElement: function() {
this.$().focus();
}
});
Expand All @@ -49,23 +50,23 @@ In `index.html` replace the static `<input>` element with our custom `{{edit-tod
`index.html`中,将静态的`<input>`元素替换为自定义的`{{edit-todo}}`组件,连接`value`和操作:

```handlebars
<!--- ... additional lines truncated for brevity ... -->
<!--- ... 为保持代码简洁,在此省略了其他代码 ... -->
{{#if isEditing}}
{{edit-todo class="edit" value=title focus-out="acceptChanges"
{{! ... additional lines truncated for brevity ... }}
{{! ... 为保持代码简洁,在此省略了其他代码 ... }}
{{#if todo.isEditing}}
{{edit-todo class="edit" value=todo.title focus-out="acceptChanges"
insert-newline="acceptChanges"}}
{{else}}
<!--- ... additional lines truncated for brevity ... -->
<!--- ... 为保持代码简洁,在此省略了其他代码 ... -->
{{! ... additional lines truncated for brevity ... }}
{{! ... 为保持代码简洁,在此省略了其他代码 ... }}
```

Pressing the `<enter>` key will trigger the `acceptChanges` event on the instance of `TodoController`. Moving focus away from the `<input>` will trigger the `focus-out` event, calling a method `acceptChanges` on this view's instance of `TodoController`.

点击`<enter>`键会触发`TodoController`实例的`acceptChanges`事件。焦点离开`<input>`时会出发`focus-out`事件,并调用视图的`TodoController`实例的`acceptChanges`方法。

Additionally, we connect the `value` property of this `<input>` to the `title` property of this instance of `TodoController`. We will not implement a `title` property on the controller so it will retain the default behavior of [proxying all requests](../controllers/#toc_representing-models) to its `model`.
Additionally, we connect the `value` property of this `<input>` to the `title` property of this instance of `TodoController`. We will not implement a `title` property on the controller so it will retain the default behavior of [proxying all requests](/guides/controllers/#toc_representing-models) to its `model`.

此外,`TodoController`实例的`title`属性与`<input>``value`属性进行了绑定。控制器中并没有定义`title`属性,这样控制就保持默认的行为,将[所有请求代理](../controllers/#toc_representing-models)到其`model`之上。
此外,`TodoController`实例的`title`属性与`<input>``value`属性进行了绑定。控制器中并没有定义`title`属性,这样控制就保持默认的行为,将[所有请求代理](/guides/controllers/#toc_representing-models)到其`model`之上。

A CSS class `edit` is applied for styling.

Expand All @@ -79,16 +80,22 @@ In `js/controllers/todo_controller.js`, add the method `acceptChanges` that we c
// ... additional lines truncated for brevity ...
// ... 为保持代码简洁,在此省略了其他代码 ...
actions: {
editTodo: function () {
editTodo: function() {
this.set('isEditing', true);
},
acceptChanges: function () {
acceptChanges: function() {
this.set('isEditing', false);

if (Ember.isEmpty(this.get('model.title'))) {
this.send('removeTodo');
} else {
this.get('model')save();
}
this.get('model').save();
}
},
removeTodo: function () {
var todo = this.get('model');
todo.deleteRecord();
todo.save();
}
},
// ... additional lines truncated for brevity ...
Expand All @@ -103,16 +110,16 @@ This method will set the controller's `isEditing` property to false and commit a

### 在线演示

<a class="jsbin-embed" href="http://jsbin.com/USOlAna/1/embed?live">Ember.js • TodoMVC</a><script src="http://static.jsbin.com/js/embed.js"></script>
<a class="jsbin-embed" href="http://jsbin.com/gureki/1/embed?output">Ember.js • TodoMVC</a><script src="http://static.jsbin.com/js/embed.js"></script>

### Additional Resources

### 附加资源

* [Changes in this step in `diff` format](https://github.com/emberjs/quickstart-code-sample/commit/a7e2f40da4d75342358acdfcbda7a05ccc90f348)
* [Controller Guide](/guides/controllers)
* [Ember.TextField API documentation](http://emberjs.com/api/classes/Ember.TextField.html)
* [Ember.TextField API documentation](/api/classes/Ember.TextField.html)

* [`diff`格式呈现本次修改](https://github.com/emberjs/quickstart-code-sample/commit/a7e2f40da4d75342358acdfcbda7a05ccc90f348)
* [控制器指南](/guides/controllers)
* [Ember.TextField API文档](http://emberjs.com/api/classes/Ember.TextField.html)
* [Ember.TextField API文档](/api/classes/Ember.TextField.html)
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ window.Todos = Ember.Application.create();

This will create a new instance of `Ember.Application` and make it available as a variable named `Todos` within your browser's JavaScript environment.

这会创建一个 `Ember.Application` 的实例,并将它作为你本地浏览器JavaScript环境的一个名为`Todos`的变量供使用。
这会创建一个 `Ember.Application` 的实例,并将它作为你本地浏览器JavaScript环境的一个名为 `Todos` 的变量供使用。

Inside `js/router.js` add the following code:

`js/router.js` 文件中添加如下代码:

```javascript
Todos.Router.map(function () {
Todos.Router.map(function() {
this.resource('todos', { path: '/' });
});
```
Expand All @@ -38,9 +38,9 @@ This will tell Ember.js to detect when the application's URL matches `'/'` and t

这会告诉Ember.js,当应用的URL与 `'/'` 匹配时,渲染(render) `todos` 模板。

Next, update your `index.html` to wrap the inner contents of `<body>` in a Handlebars script tag and include `js/application.js` and `js/router.js`:
Next, update your `index.html` to wrap the inner contents of `<body>` in a Handlebars script tag and include `js/application.js` and `js/router.js` after Ember.js and other javascript dependencies:

接着,更新 `index.html` 里的代码,将 `<body>` 里的内容包在一个Handlebars的 `<script>` 标签中,并引用 `js/application.js``js/router.js`
接着,更新 `index.html` 里的代码,将 `<body>` 里的内容包在一个Handlebars的 `<script>` 标签中,并在 Ember.js 和其他 javascript 依赖后面引用 `js/application.js``js/router.js`

```html
<!-- ... additional lines truncated for brevity ... -->
Expand All @@ -49,15 +49,17 @@ Next, update your `index.html` to wrap the inner contents of `<body>` in a Handl
<script type="text/x-handlebars" data-template-name="todos">

<section id="todoapp">
... additional lines truncated for brevity ...
{{! ... additional lines truncated for brevity ... }}
</section>

<footer id="info">
<p>Double-click to edit a todo</p>
</footer>

</script>

<!-- ... Ember.js and other javascript dependencies ... -->
<!-- ... Ember.js 和其他 javascript 依赖库 ... -->
<script src="js/application.js"></script>
<script src="js/router.js"></script>
</body>
Expand Down
40 changes: 23 additions & 17 deletions source/bilingual_guides/getting-started/adding-child-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,41 @@ In `index.html` move the entire `<ul>` of todos into a new template named `todos
`index.html`中,添加一个新的Handlebars模板标签`<script>`到文档的`<body>`中,并命名为`todos/index`,然后将整个`<ul>`移入到其中:

```html
<!--- ... additional lines truncated for brevity ... -->
<!--- ... 为保持代码简洁,在此省略了其他代码 ... -->
<body>
<script type="text/x-handlebars" data-template-name="todos/index">
<ul id="todo-list">
{{#each itemController="todo"}}
<li {{bind-attr class="isCompleted:completed isEditing:editing"}}>
{{#if isEditing}}
{{edit-todo class="edit" value=title focus-out="acceptChanges" insert-newline="acceptChanges"}}
{{#each todo in model itemController="todo"}}
<li {{bind-attr class="todo.isCompleted:completed todo.isEditing:editing"}}>
{{#if todo.isEditing}}
{{edit-todo class="edit" value=todo.title focus-out="acceptChanges" insert-newline="acceptChanges"}}
{{else}}
{{input type="checkbox" checked=isCompleted class="toggle"}}
<label {{action "editTodo" on="doubleClick"}}>{{title}}</label><button {{action "removeTodo"}} class="destroy"></button>
{{input type="checkbox" checked=todo.isCompleted class="toggle"}}
<label {{action "editTodo" on="doubleClick"}}>{{todo.title}}</label><button {{action "removeTodo"}} class="destroy"></button>
{{/if}}
</li>
{{/each}}
</ul>
</script>
<!--- ... additional lines truncated for brevity ... -->
<!--- ... 为保持代码简洁,在此省略了其他代码 ... -->
```

Still within `index.html` place a Handlebars `{{outlet}}` helper where the `<ul>` was previously:

`<ul>`原来所处位置添加一个Handlebars的`{{outlet}}`助手:

```handlebars
<!--- ... additional lines truncated for brevity ... -->
<!--- ... 为保持代码简洁,在此省略了其他代码 ... -->
{{! ... additional lines truncated for brevity ... }}
{{! ... 为保持代码简洁,在此省略了其他代码 ... }}
<section id="main">
{{outlet}}
<input type="checkbox" id="toggle-all">
</section>
<!--- ... additional lines truncated for brevity ... -->
<!--- ... 为保持代码简洁,在此省略了其他代码 ... -->
{{! ... additional lines truncated for brevity ... }}
{{! ... 为保持代码简洁,在此省略了其他代码 ... }}
```

The `{{outlet}}` Handlebars helper designates an area of a template that will dynamically update as we transition between routes. Our first new child route will fill this area with the list of all todos in the application.
Expand All @@ -56,22 +61,23 @@ In `js/router.js` update the router to change the `todos` mapping, with an addit
```javascript
Todos.Router.map(function () {
this.resource('todos', { path: '/' }, function () {
// additional child routes
// 其他子路由
// additional child routes will go here later
// 其他子路由以后在这里添加
});
});

// ... additional lines truncated for brevity ...
// ... 为保持代码简洁,在此省略了其他代码 ...

Todos.TodosIndexRoute = Ember.Route.extend({
model: function () {
model: function() {
return this.modelFor('todos');
}
});
```

When the application loads at the url `'/'` Ember.js will enter the `todos` route and render the `todos` template as before. It will also transition into the `todos.index` route and fill the `{{outlet}}` in the `todos` template with the `todos/index` template. The model data for this template is the result of the `model` method of `TodosIndexRoute`, which indicates that the model for this route is the same model as for the `TodosRoute`.
When the application loads at the url `'/'` Ember.js will enter the `todos` route and render the `todos` template as before. It will also transition into the `todos.index` route and fill the `{{outlet}}` in the `todos` template with the `todos/index` template. The model data for this template is the result of the `model` method of `TodosIndexRoute`, which indicates that the
model for this route is the same model as for the `TodosRoute`.

当应用从`'/'`加载时,Ember.js将进入`todos`路由并跟之前一样渲染`todos`模板。这也将转换到`todos.index`路由,并使用`todos/index`模板来填充`todos`模板中的`{{outlet}}`。模板使用的模型数据是`TodosIndexRoute``model`方法的返回的值。这表示该路由的模型与`TodoRoute`的模型相同。

Expand All @@ -83,7 +89,7 @@ This mapping is described in more detail in the [Naming Conventions Guide](/guid

### 在线演示

<a class="jsbin-embed" href="http://jsbin.com/oweNovo/1/embed?live">Ember.js • TodoMVC</a><script src="http://static.jsbin.com/js/embed.js"></script>
<a class="jsbin-embed" href="http://jsbin.com/teheni/1/embed?output">Ember.js • TodoMVC</a><script src="http://static.jsbin.com/js/embed.js"></script>

### Additional Resources

Expand All @@ -92,9 +98,9 @@ This mapping is described in more detail in the [Naming Conventions Guide](/guid
* [Changes in this step in `diff` format](https://github.com/emberjs/quickstart-code-sample/commit/3bab8f1519ffc1ca2d5a12d1de35e4c764c91f05)
* [Ember Router Guide](/guides/routing)
* [Ember Controller Guide](/guides/controllers)
* [outlet API documentation](http://emberjs.com/api/classes/Ember.Handlebars.helpers.html#method_outlet)
* [outlet API documentation](/api/classes/Ember.Handlebars.helpers.html#method_outlet)

* [`diff`格式呈现本次修改](https://github.com/emberjs/quickstart-code-sample/commit/3bab8f1519ffc1ca2d5a12d1de35e4c764c91f05)
* [Ember路由指南](/guides/routing)
* [Ember控制器指南](/guides/controllers)
* [outlet API文档](http://emberjs.com/api/classes/Ember.Handlebars.helpers.html#method_outlet)
* [outlet API文档](/api/classes/Ember.Handlebars.helpers.html#method_outlet)
26 changes: 15 additions & 11 deletions source/bilingual_guides/getting-started/creating-a-new-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@

## 创建新的模型实例

Next we'll update our static HTML `<input>` to an Ember view that can expose more complex behaviors. Update `index.html` to replace the new todo `<input>` with an `Ember.TextField`:
Next we'll update our static HTML `<input>` to an Ember view that can expose more complex behaviors. Update `index.html` to replace the new todo `<input>` with an `{{input}}` helper:

接下来,我们将更新我们的静态HTML`<input>`为一个Ember视图,以便能够提供更多复杂一些的行为。我们将`index.html`中的新建待办事项的`<input>`替换为一个`{{input}}`
接下来,我们将更新我们的静态HTML`<input>`为一个Ember视图,以便能够提供更多复杂一些的行为。我们将`index.html`中的新建待办事项的`<input>`替换为一个`{{input}}`助手

```handlebars
<!--- ... additional lines truncated for brevity ... -->
<!--- ... 为保持代码简洁,在此省略了其他代码 ... -->
{{! ... additional lines truncated for brevity ... }}
{{! ... 为保持代码简洁,在此省略了其他代码 ... }}
<h1>todos</h1>
{{input type="text" id="new-todo" placeholder="What needs to be done?"
value=newTitle action="createTodo"}}
<!--- ... additional lines truncated for brevity ... -->
<!--- ... 为保持代码简洁,在此省略了其他代码 ... -->
{{input
type="text"
id="new-todo"
placeholder="What needs to be done?"
value=newTitle
action="createTodo"}}
{{! ... additional lines truncated for brevity ... }}
{{! ... 为保持代码简洁,在此省略了其他代码 ... }}
```

This will render an `<input>` element at this location with the same `id` and `placeholder` attributes applied. It will also connect the `newTitle` property of this template's controller to the `value` attribute of the `<input>`. When one changes, the other will automatically update to remain synchronized.
Expand All @@ -41,13 +45,13 @@ Inside `js/controllers/todos_controller.js` implement the controller Ember.js ex
```javascript
Todos.TodosController = Ember.ArrayController.extend({
actions: {
createTodo: function () {
createTodo: function() {
// Get the todo title set by the "New Todo" text field
var title = this.get('newTitle');
if (!title.trim()) { return; }

// Create the new Todo model
var todo = this.get('store').createRecord('todo', {
var todo = this.store.createRecord('todo', {
title: title,
isCompleted: false
});
Expand Down Expand Up @@ -88,7 +92,7 @@ Reload your web browser to ensure that all files have been referenced correctly

### 在线示例

<a class="jsbin-embed" href="http://jsbin.com/ImukUZO/1/embed?live">Ember.js • TodoMVC</a><script src="http://static.jsbin.com/js/embed.js"></script>
<a class="jsbin-embed" href="http://jsbin.com/cobuzo/1/embed?output">Ember.js • TodoMVC</a><script src="http://static.jsbin.com/js/embed.js"></script>

### Additional Resources

Expand Down
78 changes: 39 additions & 39 deletions source/bilingual_guides/getting-started/creating-a-static-mockup.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,45 @@ To start, add the following text to `index.html`:
<input type="text" id="new-todo" placeholder="What needs to be done?" />
</header>

<section id="main">
<ul id="todo-list">
<li class="completed">
<input type="checkbox" class="toggle">
<label>Learn Ember.js</label><button class="destroy"></button>
</li>
<li>
<input type="checkbox" class="toggle">
<label>...</label><button class="destroy"></button>
</li>
<li>
<input type="checkbox" class="toggle">
<label>Profit!</label><button class="destroy"></button>
</li>
</ul>

<input type="checkbox" id="toggle-all">
</section>

<footer id="footer">
<span id="todo-count">
<strong>2</strong> todos left
</span>
<ul id="filters">
<li>
<a href="all" class="selected">All</a>
</li>
<li>
<a href="active">Active</a>
</li>
<li>
<a href="completed">Completed</a>
</li>
</ul>

<button id="clear-completed">
Clear completed (1)
</button>
</footer>
<section id="main">
<ul id="todo-list">
<li class="completed">
<input type="checkbox" class="toggle">
<label>Learn Ember.js</label><button class="destroy"></button>
</li>
<li>
<input type="checkbox" class="toggle">
<label>...</label><button class="destroy"></button>
</li>
<li>
<input type="checkbox" class="toggle">
<label>Profit!</label><button class="destroy"></button>
</li>
</ul>

<input type="checkbox" id="toggle-all">
</section>

<footer id="footer">
<span id="todo-count">
<strong>2</strong> todos left
</span>
<ul id="filters">
<li>
<a href="all" class="selected">All</a>
</li>
<li>
<a href="active">Active</a>
</li>
<li>
<a href="completed">Completed</a>
</li>
</ul>

<button id="clear-completed">
Clear completed (1)
</button>
</footer>
</section>

<footer id="info">
Expand Down
Loading

0 comments on commit 4b30f9c

Please sign in to comment.