この問題は誰でも助けてくれますか?私はReact on Meteorを実行しています。このコンポーネントを使用してTrackerReactを使用してMongoにデータを追加します。別のコンポーネントにこれらのデータを取り込み、ページロード後にconsole.logデータが残っているので、Mongoデータが読み込まれる前にページが読み込まれていると思います。ありがとうございました。 .jsxの私はモンゴに保存場所:私はそれらをロードしたいのはここ反応を使ってMongoからのデータを表示することはできません
import React from 'react';
import TrackerReact from 'meteor/ultimatejs:tracker-react'
Gifts= new Mongo.Collection("gifts");
export default class AdminAdd extends TrackerReact(React.Component){
addGift(event){
event.preventDefault();
giftName=this.refs.giftname.value.trim();
giftCity=this.refs.giftcity.value.trim();
giftActive=this.refs.giftactive.checked;
Gifts.insert({
name: giftName,
city: giftCity,
active: giftActive,
});
this.refs.giftname.value="";
this.refs.giftcity.value="";
this.refs.giftactive.checked=false;
}
render(){..RenderStuff..}
は次のとおりです。
import React from 'react';
import Gift from './components/Gift.jsx'
export default class Main extends React.Component{
allgifts(){
return Gifts.find().fetch();
}
render(){
console.log(allgifts());
return(
<div className="row">
{this.allgifts().map((gift)=>{
return
<Gift gift={gift} key={gift._id}/>})}
</div>
)}}
とギフトコンポーネント:
import React from 'react';
export default class Gift extends React.Component{
render(){
return(
<div>
<div>
<div>{this.props.gift.name}</div>
<div>{this.props.gift.city}</div>
<div>{this.props.gift.active}</div>
</div>
</div>
)}}
、これはその後、最初の戻り空のオブジェクトで、ときに私Gifts.find()(フェッチ)それは手動それは後に動作コンソールログです:。
うわー、これは実際に私がMongodbと通信しているとき、天気のデータを送信したり受信したりするとき、TrackerReactでラップする必要があります。再度、感謝します –