这是我的HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<script type="text/x-handlebars">
<p>{{#link-to 'mytest'}}My Test{{/link-to}}</p>
<p>{{#link-to 'posts'}}POSTS{{/link-to}}</p>
{{outlet}}
</script>
<script type="text/x-handlebars" id="mytest">
<p>...</p>
</script>
<script type="text/x-handlebars" id="posts">
<ul>
{{#each model}}
<li>{{id}} -- {{#link-to 'post' this}}{{title}}{{/link-to}}</li>
{{/each}}
</ul>
<p>
{{outlet}}
</p>
</script>
<script type="text/x-handlebars" id="post">
<h1>{{title}}</h1>
<p>{{excerpt}}</p>
</script>
<script src="js/libs/jquery-1.10.2.js"></script>
<script src="js/libs/handlebars-1.1.2.js"></script>
<script src="js/libs/ember-1.7.0.js"></script>
<script src="js/app.js"></script>
<!-- to activate the test runner, add the "?test" query string parameter -->
<script src="tests/runner.js"></script>
</body>
</html>
这是我的JS:
App = Ember.Application.create();
App.Router.map(function () {
this.resource('mytest');
this.resource('posts', function (){
this.resource('post', { path: ':post_id' });
});
});
App.PostsRoute = Ember.Route.extend({
model: function() {
return posts;
}
});
App.PostRoute = Ember.Route.extend({
model: function(params) {
return posts.findBy('id', params.post_id);
}
});
var posts = [
{
'id': 1,
'title': 'first!',
'excerpt': 'firccccccccst!'
},
{
'id': 2,
'title': 'second!',
'excerpt': 'sssdsddsd!'
},
];
当我改变这个时:
App.PostRoute = Ember.Route.extend({
model: function(params) {
return posts.findBy('id', params.post_id);
}
});
到此:
App.PostRoute = Ember.Route.extend({
model: function(params) {
return {
'id': 1,
'title': 'first!',
'excerpt': 'firccccccccst!'
}
}
});
它有效。
出了什么问题?