と反応し、私はサブスクリプションからの配列を返す関数で.map()
を使用して単一の文書をレンダリング:は、文書のリストをレンダリングするために流星
export default class ApplicationForm extends TrackerReact(React.Component) {
constructor() {
super();
this.state = {
subscription: {
applications: Meteor.subscribe('applications')
}
}
}
componentWillUnmount() {
this.state.subscription.applications.stop();
}
getSingleApplication() {
const applicationDoc = Applications.find().fetch();
if (applicationDoc) {
return applicationDoc[0];
}
}
render() {
const name = this.getSingleApplication().name;
return (
<div>
{name}
</div>
);
}
}
私は次のエラーを取得する:
Cannot read property 'name' of undefined
私は私が持っていると思いますいくつかの基本的なjavascriptで欠けていた。
または、ページの読み込み時にサブスクリプションが準備されていないとどうしてですか?
もっとコードを表示できますか? – Li357
'this.getSingleApplication()'は未定義を返します。それ以外にもできることは他にありません。 –
'未定義のプロパティ 'name'を読み取ることができません - javascript ... getSingleApplicationが未定義を返す必要があることを意味します。 – Endless