小编May*_*yas的帖子

ReactJS组件不使用状态变量呈现textarea

我在React面临一个有趣的错误.

我有这个组件:

'use strict';
import SummaryStore from '../stores/SummaryStore';
import React from 'react';

export default class ChangeSummaryForm extends React.Component {
   constructor() {
       // store initialisation
       SummaryStore.register();

       var vRating = SummaryStore.getBookForSummaryPrint().summaryRating;
       var vStarClassName = this.getRatingClasses(vRating);
       this.state = {
            sStarClassName: vStarClassName,
            sCurrentBookToShow: SummaryStore.getBookForSummaryPrint()
       };

        this.thereIsASummaryToShow = this.thereIsASummaryToShow.bind(this);
    }

  getRatingClasses(pRating) {
      var vI, vStarClassName = [];
       for(vI = 0; vI < 4; vI++) {
          if(pRating > 0) {
             vStarClassName.push("glyphicon glyphicon-star");
             pRating--;
          } else {
             vStarClassName.push("glyphicon glyphicon-star-empty");
          }
       }
      return vStarClassName;
  }
  componentDidMount() {
    SummaryStore.addChangeListener(this.thereIsASummaryToShow); …
Run Code Online (Sandbox Code Playgroud)

javascript textarea reactjs

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

未捕获的TypeError:无法读取未定义的反应状态项的属性'toUpperCase'

我是React和Javascript的新手,我正在尝试渲染以下React组件:

'use strict';
var React = require('react');
import ToReadList from './toreadlist.js';

var ToRead = React.createClass({
getInitialState: function() {
    return { bookTitles: [] };
},
handleSubmit: function(e) {
    e.preventDefault();
    this.state.bookTitles.push(React.findDOMNode(this.refs.bookTitleInput).value.trim());
    this.setState({items: this.state.bookTitles});
},
render: function() {
    return (<div>
        <form onSubmit={this.handleSubmit}><input type="text" ref="bookTitleInput"></input>
            <input type="submit"></input></form>
            <ToReadList bookTitles={this.state.bookTitles} />
    </div>
           );
}
});

module.exports = ToRead;
Run Code Online (Sandbox Code Playgroud)

但我在我的控制台上遇到以下错误:" 未捕获的TypeError:无法读取未定义的属性'toUpperCase' "

我试图调试(因为错误对我来说是模糊的,我的代码中没有指示行)并且注意到这个特定的行:

this.state.bookTitles.push()
Run Code Online (Sandbox Code Playgroud)

导致错误.

请帮忙!

编辑 错误是由webpack var injection函数引起的:

function autoGenerateWrapperClass(type) {
      return ReactClass.createClass({
        tagName: type.toUpperCase(),
        render: function() {
          return new ReactElement(
            type,
            null,
            null, …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs webpack

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

为什么我的http库的错误处理程序在应用程序中捕获*all*runtime错误?

我正在使用React Native 0.39构建一个原型应用程序,它从远程源请求一些数据.要发出请求,我使用Axios.

这个电话似乎很简单.在一个名为的组件中TownsList.js,我这样做

class TownsList extends Component {

  constructor(props) {
    super(props);
    this.state = {towns: []};
  }

  componentDidMount() {

    let url = "(SOME URL HERE)";

    axios.get(url)
         .then(function(response) {
           // Do stuff witt the successful result
         })
         .catch(function (error) {
           Alert.alert(
             'Download failed',
             'Unable to download data from '+url+"\nError:"+error,
             [{text: 'OK'}])
         });

...
Run Code Online (Sandbox Code Playgroud)

现在奇怪的是,每当我在// Do stuff witt the successful result块中的代码中遇到其他运行时错误时- 例如对某个常量或变量的错误引用 - 该错误也将由Axios的错误处理程序处理:

在此输入图像描述

这感觉不对.我究竟做错了什么?我是否应该在我的应用程序中的其他位置设置"通用"错误处理以捕获这些内容?或者这是预期的行为?

reactjs react-native

7
推荐指数
1
解决办法
3032
查看次数

Elasticsearch术语查询不会给出任何结果

我是Elasticsearch的新手,我必须执行以下查询:

GET book-lists/book-list/_search
{  
   "query":{  
      "filtered":{  
         "filter":{  
            "bool":{  
               "must":[  
                  {  
                     "term":{  
                        "title":"Sociology"
                     }
                  },
                  {  
                     "term":{  
                        "idOwner":"17xxxxxxxxxxxx45"
                     }
                  }
               ]
            }
         }
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

根据Elasticsearch API,它等同于伪SQL:

SELECT document
FROM   book-lists
WHERE  title = "Sociology"
       AND idOwner = 17xxxxxxxxxxxx45
Run Code Online (Sandbox Code Playgroud)

问题是我的文档看起来像这样:

{  
   "_index":"book-lists",
   "_type":"book-list",
   "_id":"AVBRSvHIXb7carZwcePS",
   "_version":1,
   "_score":1,
   "_source":{  
      "title":"Sociology",
      "books":[  
         {  
            "title":"The Tipping Point: How Little Things Can Make a Big Difference",
            "isRead":true,
            "summary":"lorem ipsum",
            "rating":3.5
         }
      ],
      "numberViews":0,
      "idOwner":"17xxxxxxxxxxxx45"
   }
}
Run Code Online (Sandbox Code Playgroud)

并且上面的Elasticsearch查询不会返回任何内容.

然而,此查询返回上面的文档:

GET book-lists/book-list/_search
{  
   "query":{  
      "filtered":{  
         "filter":{  
            "bool":{ …
Run Code Online (Sandbox Code Playgroud)

elasticsearch

6
推荐指数
1
解决办法
9699
查看次数