Note:这是抛出的反应错误。
所以我正在尝试一个实验,我根据该页面从主干路由器渲染一个后组件。现在我知道你通常不会这样做,事情可能会变得混乱等等。但再一次这只是一个实验.
所以我在主干中有以下路由(注意反应调用):
AisisWriter.Routers.Posts = Backbone.Router.extend({
writer_posts: null,
posts: null,
mountNode: $('#blog-manage'),
routes : {
'': 'index'
},
initialize: function() {
this.writer_posts = new AisisWriter.Collections.Posts();
},
index: function() {
var options = { reset: true };
this.writer_posts.fetch(options).then(this.postsRecieved, this.serverError);
},
// Deal with the posts received
postsRecieved: function(collection, response, options) {
this.posts = collection;
// Walk through the posts.
$.each(this.posts, function(key, value){
// value is an array of objects.
$.each(value, function(index, post_object){
React.renderComponent(new Post({post: post_object}), this.mountNode);
});
});
},
// Deal with any server errors
serverError: function() {
console.log('There was an error trying to fetch the posts.');
}
});
这个想法是,它应该在页面上吐出一个帖子标题,一个接一个(我有一种感觉它只会做一次)。
但问题是控制台说:
Uncaught Error: Invariant Violation: _registerComponent(...): Target container is not a DOM element.
这是因为我尝试渲染组件的方式吗?