Ember.js 余烬数据嵌套资源URL
我正在进一步开发博客,从emberjs.com博客教程视频开始。当我试图保存注释以提供余烬数据时,rest适配器正在发布到Ember.js 余烬数据嵌套资源URL,ember.js,ember-data,Ember.js,Ember Data,我正在进一步开发博客,从emberjs.com博客教程视频开始。当我试图保存注释以提供余烬数据时,rest适配器正在发布到 http://localhost/blog/comments但应该是http://localhost/blog//posts/1/comments因为它是嵌套资源。下面是我的代码 var App = Ember.Application.create({ LOG_TRANSITIONS: true, ready: function() { th
http://localhost/blog/comments
但应该是http://localhost/blog//posts/1/comments
因为它是嵌套资源。下面是我的代码
var App = Ember.Application.create({
LOG_TRANSITIONS: true,
ready: function() {
this.set('Router.enableLogging', true);
}
});
App.Router.map(function() {
this.resource('about');
this.resource('posts', function() {
this.resource('post', {
path: ':post_id'
});
this.route('new');
});
});
App.IndexRoute = Ember.Route.extend({
redirect: function() {
this.transitionTo('posts');
}
});
App.PostsRoute = Ember.Route.extend({
model: function() {
return App.Post.find();
}
});
App.Comment = DS.Model.extend({
name: DS.attr('string'),
email: DS.attr('string'),
text: DS.attr('string'),
createdAt: DS.attr('date')
});
App.Post = DS.Model.extend({
title: DS.attr('string'),
author: DS.attr('string'),
intro: DS.attr('string'),
extended: DS.attr('string'),
publishedAt: DS.attr('date'),
comments: DS.hasMany('App.Comment', {embedded:'always'})
});
App.Store = DS.Store.extend({
revision: 12,
adapter: DS.RESTAdapter.extend({
url: 'http://localhost/blog'
})
});
App.CommentNewController = Ember.ObjectController.extend({
needs: ["post"],
saveComment: function(params) {
console.log("Dinesh is coding");
console.log("iname:" + params.iname);
console.log("text:" + params.text);
console.log("email:" + params.email);
//params.set('name', params.iname);
var post = this.get('controllers.post').get('model');
debugger;
var comments = post.get('comments');
comments.createRecord({
name:params.iname,
text:params.text,
email:params.email,
post_id:post.get('id')
});
//this.get('controllers.comments').pushObject(params);
this.get('store').commit();
},
content: {}
// }
});
App.CommentNewView = Ember.View.extend({
template: Ember.Handlebars.compile(comment_new_html)
// controller: App.CommentController
});
我的新观点:
<form {{action "saveComment" content on="submit" validation="true"}}>
<p>{{view Ember.TextField valueBinding="iname" id="iname" placeholder="Name" required="true"}}<br /></p>
<p>{{view Ember.TextField valueBinding="email" id="email" placeholder="Email" required="true"}}<br /></p>
<p>{{view Ember.TextArea valueBinding="text" id="text" placeholder="Comment" }}</p>
<button type="submit" class="btn">Save Comment</button>
</form>
{{view Ember.TextField valueBinding=“iname”id=“iname”placeholder=“Name”required=“true”}
{{view Ember.TextField valueBinding=“email”id=“email”placeholder=“email”required=“true”}}
{{view Ember.TextArea valueBinding=“text”id=“text”placeholder=“Comment”}
保存评论
有没有人遇到过类似的问题?如何为嵌套url配置余烬数据?我遇到了类似的问题,并使用了以下路由:
App.Router.map(function() {
this.resource('posts');
this.resource('post', { path: '/posts/:post_id' }, function() {
this.resource('comments', function() {
this.route('new');
this.route('create');
});
this.route('comment', { path: 'comments/:comment_id'});
});
});
这给出了一个类似于
/posts/:post\u id/comments/:comment\u id
更多信息可从我的博客文章中获得,关于的?如果是这样,你能关闭这个吗?我不知道ruby是如何工作的,我使用laravel作为我的后端,它适用于
http://localhost/blog//posts/1/comments
不适用于http://localhost/blog/comments