Javascript React JS获得错误:解析错误:第27行:意外令牌。在http://localhost/PHP-React-Demo/ajax_call.html 返回{cell.data.row}

Javascript React JS获得错误:解析错误:第27行:意外令牌。在http://localhost/PHP-React-Demo/ajax_call.html 返回{cell.data.row},javascript,reactjs,Javascript,Reactjs,我想在一个窗口中显示来自数据库的内容 反应JS得到错误的 Error: Parse Error: Line 27: Unexpected token . at http://localhost/PHP-React-Demo/ajax_call.html return {cell.data.row} 我的代码是: Index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www

我想在一个窗口中显示来自数据库的内容

反应JS得到错误的

Error: Parse Error: Line 27: Unexpected token .     at http://localhost/PHP-React-Demo/ajax_call.html  return {cell.data.row}
我的代码是:

Index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<link rel="stylesheet" type="text/css" href="css/machineTest.css">
<head>

<title>Index</title>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db_name = "anand";
$conn = new PDO("mysql:host=$servername;dbname=$db_name",$username,$password);
$result = $conn->prepare("SELECT * FROM student");
$result->execute();
?>
<?php
 foreach($result as $row){

    echo "$row[0]$row[1]$row[2]$row[3]$row[4]";

}

?>
    </body>
</html>

and react code is :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Initial Data Via AJAX</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
  </head>
      <body>
      <div id="example"></div>
          <script type="text/jsx">
              var ImageCollect = React.createClass({
                    getInitialState: function() {
                        return {
                          phpData: []
                        };
                    },

                    componentDidMount: function() {
                        var self = this;
                        $.get(this.props.source, function(result) {
                          var collection = result.data.children;
                          if (this.isMounted()) {
                            this.setState({
                              phpData: collection
                            });
                          }
                        }.bind(this));
                    },

                    render: function() {
                        BDdata = this.state.phpData || [];
                          return (
                            <div>
                              Images: 
                              {BDdata.map(function(cell){
                                  return {cell.data.row}// I think i want to change this line.
                              })}
                            </div>
                        );
                    }
              });

                React.render(
                <ImageCollect source="http://localhost/PHP-React-Demo/index.php" />,
                  document.getElementById('example')
                );

          </script>

      </body>
</html>

指数
反应代码是:
通过AJAX的初始数据
var ImageCollect=React.createClass({
getInitialState:函数(){
返回{
phpData:[]
};
},
componentDidMount:function(){
var self=这个;
$.get(this.props.source,函数(result){
var collection=result.data.children;
if(this.isMounted()){
这是我的国家({
phpData:集合
});
}
}.约束(这个);
},
render:function(){
BDdata=this.state.phpData | |[];
返回(
图像:
{BDdata.map(函数(单元格){
return{cell.data.row}//我想我要更改这一行。
})}
);
}
});
反应(
,
document.getElementById('示例')
);

我只想在JSX上下文中显示从react页面上的index.php检索的内容,
{}
表示JavaScript表达式。在JavaScript上下文中,
{}
表示块或对象文本

return{cell.data.row}
位于JavaScript上下文中(
.map
回调),由于
{…}
的位置,它们被解释为对象文本

但是
{cell.data.row}
不是有效的对象文字,我怀疑您是否仍想在这里创建对象。使用

return cell.data.row;

相反。

结果.data.children是什么?它是什么样子的?这是以前的代码。我可以删除它吗?或者我应该用什么来代替这个?