2

我正在尝试学习使用流星的反应方式并遇到一个非常关键但非常基本的问题。我正在尝试订阅一些数据,然后将其呈现为反应组件,并用于react-template-helper显示该组件。

一旦我尝试渲染该组件,我就会在控制台中收到以下错误。

Exception from Tracker afterFlush function: undefined
findOne is not a function

或者

find is not a function

我的应用模板:

<template name="appLayout">
    <nav class="fixed">
        <ul class="centered">
            <li><a href=""></a></li>
            <li><a href=""></a></li>
            <li><a href=""></a></li>
        </ul>

        <ul class="social">
            <li><a href=""><i class="icon"></i></a></li>
            <li><a href=""><i class="icon"></i></a></li>
        </ul>
    </nav>
    {{> Template.dynamic template=yield}}
</template>

<template name="home">
    <section class="home-hero">
        {{> React component=homeContent}}
    </section>
</template>

我的反应/流星视图逻辑:

Template.home.onCreated( function() {
    let template = this;
    template.autorun( function() {
        Meteor.subscribe('homecontent');
    })
});

homeContent = React.createClass({
    mixins: [ReactMeteorData],
    getMeteorData() {
        return {
            homeData: homeContent.find({}).fetch()
        }
    },
    render(){
        return (
            <div className="units-container">
                <div className="units-row centered-content stacked">
                    <h1>site name</h1>
                    <p>{this.data.homeData.homeCopy}</p>
                </div>
            </div>
        )
    }
})

Template.home.helpers({
    homeContent() {
        return homeContent
    }
})

我的路由器:

FlowRouter.route('/', {
    action() {
        BlazeLayout.render('appLayout', {
            yield: 'home'
        })
    },
    name: 'home'
})

我的服务器出版物:

Meteor.publish('homecontent', function(){
    return homeContent.find();
})

我正在使用以下软件包尝试通过 blaze 实现 react 组件:ecmascript、react、kadira:flow-router、kadira:blaze-layout、react-template-helper。

值得注意的是,如果我只是从我的 jsx 文件中删除mixins和删除getMeteorData,一切都会呈现正常,并且 mini-mongo 从控制台正常运行。

4

1 回答 1

0

很简单的错误。在这一行homeData: homeContent.find({}).fetch(),调用homeContent指的是我刚刚制作的反应类,而不是我正在寻找的集合。

此特定错误的修复程序homeContent = React.createClass({变为homeComponent = React.createClass({

于 2015-12-27T14:59:38.427 回答