【问题标题】:Using react with meteor results in find not a function使用 react with meteor 导致 find not a function
【发布时间】:2015-12-26 03:31:28
【问题描述】:

我正在尝试学习使用流星的反应方式并遇到一个非常关键但非常基本的问题。我正在尝试订阅一些数据,然后将其呈现为反应组件,并使用 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 文件中删除 mixinsgetMeteorData,一切都会正常呈现,并且 mini-mongo 从控制台正常运行。

【问题讨论】:

    标签: javascript meteor reactjs meteor-blaze flow-router


    【解决方案1】:

    非常简单的错误。在homeData: homeContent.find({}).fetch() 行,调用homeContent 指的是我刚刚创建的反应类,而不是我正在寻找的集合。

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

    【讨论】:

      猜你喜欢
      • 2022-10-13
      • 1970-01-01
      • 1970-01-01
      • 2019-03-01
      • 2021-06-02
      • 2020-04-14
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      相关资源
      最近更新 更多