为什么我必须在下面的模板中指定 model.name?我的印象是控制器装饰了它的模型。我想我应该能够在下面的模板中只做 {{ name }}。但它只有在我做 {{ model.name }} 时才有效。
非常感谢任何帮助。谢谢!
应用程序.js
App = Ember.Application.create({});
App.Router.map(function () {
this.resource("posts", { path: "/" }, function () {
this.route("new", { path: "/new" });
this.route("post", { path: ":post_id" });
});
this.route("another", { path: "/another" });
});
App.PostsRoute = Ember.Route.extend({
model: function(params) {
return [{ name: "foo" },{ name: "bar" },{ name: "zoo" }]
}
});
App.PostsPostRoute = Ember.Route.extend({
model: function(params) {
console.log('model');
return Ember.Object.create({ name: "MODEL name" })
}
});
App.PostsPostController = Ember.Controller.extend({
selected: false
});
索引.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Test</title>
</head>
<body>
<script type="text/x-handlebars" id="posts">
posts here
{{#each controller}}
{{name}}
{{/each}}
{{ outlet }}
</script>
<script type="text/x-handlebars" id="posts/index">
posts index here
</script>
<script type="text/x-handlebars" id="posts/new">
posts new here
</script>
<script type="text/x-handlebars" id="posts/post">
here is a post???
{{ model.name }}
{{ selected }}
</script>
<script src="jquery-1.10.2.js"></script>
<script src="handlebars.js"></script>
<script src="ember.js"></script>
<script src="app.js"></script>
</body>
</html>