我收到以下错误,并且已经尝试了几个小时才能摆脱它而没有成功:
未捕获的TypeError:无法读取未定义的属性“posts” main.jsx:17
我命名为main.jsx的组件具有以下代码:
import React, { Component, PropTypes } from 'react';
//import { createContainer } from 'meteor/react-meteor-data';
//import Posts from './both/collections/post.js';
Main = React.createClass({
mixims:[ReactMeteorData],
getMeteorData(){
let data = {};
data.posts = [];
data.ads = [];
data.posts = Posts.find({},{sort:{createdAt:-1}}).fetch();
data.ads = DBAds.find({},{}).fetch();
return data;
},
render() {
var adobj = {_id:1,text:'My First Ad',title:'Some Company' ,image: 'http://placehold.it/160x160'};
var posts = this.data.posts.map(function(record){
return <Post key={record._id} post={record}/>
});
return (
<div className="col-sm-9 col-sm-11" id="main" >
<div>
<div className="full col-sm-9">
<div className="row">
<div className="col-sm-9">
<Statusform/>
{posts}
<button className="btn btn-md">More</button>
</div>
<div className="col-sm-3">
<Ads ads={adobj}/>
</div>
</div>
</div>
</div>
</div>
)
}
});
请帮我解决这个错误,主要是为了理解我犯错的原因。感谢您的期待。
答案 0 :(得分:0)
你有一个错字。它是mixins
,而不是mixims
。