小编Mju*_*ice的帖子

如何调试此错误:未捕获(在promise中)错误:对象作为React子对象无效

控制台中的完整错误:

未捕获(在承诺中)错误:对象无效作为React子对象(找到:具有键{id,name,description,css,ephemeral,readonly,topPost}的对象)
如果您要渲染子集合,请使用数组相反,或使用React附加组件中的createFragment(object)包装对象.检查exports.(...)的渲染方法

我真的不知道这个错误意味着什么,它并没有指向代码中的一行,所以我不知道该怎么做.

我正在使用api.jsx从Imgur获取数据(特别是我在topic-store.jsx中调用它),然后尝试在topic-list.jsx中呈现数据

main.jsx

var React = require('react');
var Header = require('./header');
var TopicList = require('./topic-list');

module.exports = React.createClass({
    render: function () {
        return <div>
          <Header />
          {this.content()}
        </div>
    },
    content: function () {
        if (this.props.children) {
            return this.props.children
        } else {
            return <TopicList/>
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

header.jsx

var React = require('react');
var Router = require('react-router');
var Link = Router.Link; //Router's Link object is a renderable component, that turns into …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

14
推荐指数
1
解决办法
3万
查看次数

将应用程序部署到Heroku时出错

使用git hub将我的应用程序部署到heroku时出现某种错误.问题是,我不明白heroku日志和引起的错误.这是heroku日志:

Marcuss-MacBook-Pro:Weather-App marcushurney$ heroku logs
2016-01-05T14:37:27.798077+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-01-05T14:37:27.798377+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-01-05T14:37:27.786949+00:00 app[web.1]: npm ERR! node v5.1.1
2016-01-05T14:37:27.786556+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-01-05T14:37:27.787856+00:00 app[web.1]: npm ERR! npm  v3.3.12
2016-01-05T14:37:28.776245+00:00 heroku[web.1]: Process exited with status 1
2016-01-05T14:37:28.789412+00:00 heroku[web.1]: State changed from starting to crashed
2016-01-05T17:27:16.684869+00:00 heroku[web.1]: State changed from crashed to starting
2016-01-05T17:27:17.853743+00:00 heroku[web.1]: Starting process with command `npm start`
2016-01-05T17:27:20.423495+00:00 app[web.1]: npm ERR! node …
Run Code Online (Sandbox Code Playgroud)

git heroku

10
推荐指数
2
解决办法
2万
查看次数

错误"google.charts.load()无法使用.45或更早版本调用多次"

我正在使用带有React和Redux的Google Charts API.获取"错误google.charts.load()不能在版本45或更早版本中多次调用"

我不确定如何解决这个问题,因为每次因用户与应用程序交互而导致数据发生变化时我都需要重新渲染我的图表.我在ComponentWillMount中加载数据后绘制了三个图表

componentWillMount() {

        //Loads all sales belonging to a user

        this.props.fetchSales(this.props.activeUser._id).then(() => {

            // 3 below functions load total revenue for today, the week, and the month

            this.calculateTodaysRevenue();
            this.calculateWeekRevenue();
            this.calculateMonthRevenue();
        });

    }
Run Code Online (Sandbox Code Playgroud)

如果我们看一下calculateTodaysRevenue(),你会看到这是我在this.setState({})结束后在最后调用google.charts.load()的地方:

calculateTodaysRevenue() {

        //all of today's date values pulled from state

        const { currentDay, currentMonth, currentYear } = this.state;

        let todaysTotalRevenue = 0;
        let dataRowsForTodaysRevenue = [];

        this.props.allSales.map((sale) => {

            //checks the date key of each sale to see if it matches today's date

            if …
Run Code Online (Sandbox Code Playgroud)

javascript charts google-visualization reactjs

3
推荐指数
1
解决办法
3542
查看次数

在循环再次迭代之前,如何等待promise的"then"块在嵌套的forEach循环中执行?

我有3个forEach循环,我希望前两个等待一个promise然后阻止执行,然后再重新开始迭代.我已经使用标记为1,2和3的console.log语句证明了这一点.

我希望控制台日志按顺序排列,如"1,2,3,1,2,3等"而不是我得到的是"1,2,1,2,1,2,1,2,1" ,2,3,3,3,3,3,3"如何使所有这些顺序?fetchCandidatesByCity是mongoose find方法,它返回一个promise.

axios.get(FEED_URL).then(data => {
let candidatesWithMessageSent = [];

data.data.jobs.forEach(job => {
  console.log("1");
  // console.log(candidatesWithMessageSent);
  job.city.forEach(cityAndState => {
    console.log("2");

    let jobState = extractState(cityAndState);

    let jobLocation = addSpaceAfterComma(cityAndState.toLowerCase());

    let jobCity = extractCity(jobLocation);


    fetchCandidatesByCity(jobCity)
      .then(candidates => {
        candidates.forEach((candidate, index) => {
          console.log("3");
          const candidateId = candidate._id.toString();

          if (index <= MAX_MESSAGE_LIMIT &&
            !containsUberLyft(job.title) &&
            priceIsHigh(job.price) &&
            !candidateHasMessage(candidatesWithMessageSent, candidateId)) {

            const jobURL = `http://www.jobs2careers.com/click.php?id=${job.id}.${PUBLISHER_ID}`;

            // candidate has received a job notification, so add candidate to candidatesWithMessageSent

            candidatesWithMessageSent = [ ...candidatesWithMessageSent, candidateId ]; …
Run Code Online (Sandbox Code Playgroud)

javascript foreach node.js

0
推荐指数
1
解决办法
109
查看次数

当我将IIFE的类型记录到控制台时,它是一个对象而不是一个函数,为什么?

我有一个返回对象的IIFE.在我的app.js文件中,我将其添加到index.html中的脚本标记中,我登录到我的IIFE的控制台类型,它是一个对象.它不应该是一个功能吗?为什么typeof返回一个对象?

这是app.js中的IIFE:

var UIController = (function() {

  var DOMstrings = {
    inputType: '.add__type',
    description: '.add__description',
    value: '.add__value',
    addBtn: '.add__btn'
  };

  return {
    getInput: function() {
      // return an object containing all values from UI elements
      return {
        type: document.querySelector(DOMstrings.inputType).value, // will be either income or expense
        description: document.querySelector(DOMstrings.description).value, // description of transaction
        value: document.querySelector(DOMstrings.value).value // value of transaction
      };
    },
    getDOMStrings: function() {
      return DOMstrings;
    }
  };

})();

console.log(typeof UIController);
Run Code Online (Sandbox Code Playgroud)

javascript iife

-1
推荐指数
1
解决办法
95
查看次数