Ember.js中的Hello World:what';这里怎么了?

Ember.js中的Hello World:what';这里怎么了?,ember.js,Ember.js,我准备了一把小提琴来更好地揭露这个问题 代码: 视图: <script type="text/x-handlebars"> {{collection App.myCollectionView}} </script> <script type="text/x-handlebars" data-template-name="MyView"> <h1>Hello, {{name}}!</h1> </script>​

我准备了一把小提琴来更好地揭露这个问题

代码:

视图:

<script type="text/x-handlebars">
   {{collection App.myCollectionView}}
</script>

<script type="text/x-handlebars" data-template-name="MyView">
  <h1>Hello, {{name}}!</h1>
</script>​

{{collection App.myCollectionView}
你好,{{name}}!
​

我做错了什么?

首先,
{{collection}
帮助程序需要一个
Ember.View
类,而不是
Ember.View
实例。您必须将
Ember.CollectionView.create()
替换为
Ember.CollectionView.extend

接下来,在您的模板中,您必须将
{{name}}
替换为
{{view.content.name}}
,根据

以下是您更新的JSFIDLE:

编辑

写入
{{name}}
意味着
context.name
,其中context通常是控制器()。由于
Ember.ObjectController
Ember.ArrayController
只是代理,这些属性被委托给它们的内容()

因此您必须编写
{{view.content.name}
,因为您需要
view.content
name
属性

正如@tomdale所说:

在项目视图的模板中,
view
应该引用项目视图, 和
view.content
应该引用内容数组中的项目


您可以看到带有控制器的JSFIDLE,无需指定
view

首先,
{{collection}
帮助程序需要
Ember.view
类,而不是
Ember.view
实例。您必须将
Ember.CollectionView.create()
替换为
Ember.CollectionView.extend

接下来,在您的模板中,您必须将
{{name}}
替换为
{{view.content.name}}
,根据

以下是您更新的JSFIDLE:

编辑

写入
{{name}}
意味着
context.name
,其中context通常是控制器()。由于
Ember.ObjectController
Ember.ArrayController
只是代理,这些属性被委托给它们的内容()

因此您必须编写
{{view.content.name}
,因为您需要
view.content
name
属性

正如@tomdale所说:

在项目视图的模板中,
view
应该引用项目视图, 和
view.content
应该引用内容数组中的项目

您可以看到带有控制器的JSFIDLE,无需指定
视图

谢谢@lousicoquio,我在研究期间阅读了要点,但我的理解是,在新版本的Ember上,
{{name}
将引用
内容
中的属性,而不是视图。那么为什么我需要显式地使用
{{view.content.XXX}
?谢谢@lousicoquio,我在研究期间阅读了要点,但我的理解是,在新版本的Ember上,
{{name}}
会引用
内容中的属性,而不是视图。那么为什么我需要显式地使用
{{view.content.XXX}
<script type="text/x-handlebars">
   {{collection App.myCollectionView}}
</script>

<script type="text/x-handlebars" data-template-name="MyView">
  <h1>Hello, {{name}}!</h1>
</script>​