Why do I have to specify model.name instead of just name?
Why do I have to specify model.name in the template below? I was under the
impression that a controller decorates its model. I thought I should be
able to do just {{ name }} in the template below. But it only works if I
do {{ model.name }}.
Any help greatly appreciated. Thanks!
app.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
});
index.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>
No comments:
Post a Comment