Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 反应本机-意外标识符_Javascript_Reactjs_Ecmascript 6_React Native - Fatal编程技术网

Javascript 反应本机-意外标识符

Javascript 反应本机-意外标识符,javascript,reactjs,ecmascript-6,react-native,Javascript,Reactjs,Ecmascript 6,React Native,我在以下程序的fetchMovies(){行上遇到意外的标识符错误: /** * Sample React Native App * https://github.com/facebook/react-native */ 'use strict'; var React = require('react-native'), { StyleSheet, Component, AppRegistry, ListView, View, Text, Image } =

我在以下程序的
fetchMovies(){
行上遇到意外的标识符错误:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';

var React = require('react-native'),

{
  StyleSheet,
  Component,
  AppRegistry,
  ListView,
  View,
  Text,
  Image
} = React,

baseUrl = 'http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json',
apiKey = '7waqfqbprs7pajbz28mqf6vz',
pageLimit = 25,
queryString = '?apikey=' + apiKey + '&page_limit=' + pageLimit,
url = baseUrl + queryString,

styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'white',
  },
  rightContainer: {
    flex: 1,
  },
  title: {
    marginBottom: 8,
    textAlign: 'center'
  },
  year: {
    fontSize: 10,
    textAlign: 'center'
  },
  thumbnail: {
    width: 53,
    height: 81
  },
  listView: {
    paddingTop: 20,
    backgroundColor: 'black'
  }
})

class movieList extends Component{

  getInitialState() {
    return {
      dataSource: new ListView.DataSource({
        rowHasChanged: (row1, row2) => row1 !== row2
      }),
      loaded: false
    }
  },

  fetchMovies() {
    return fetch(url)
    .then((response) => response.json())
    .then((data) => data.movies)
  },

  componentDidMount() {
    this.fetchMovies()
    .then((movies) => {
      this.setState({
        dataSource: this.state.dataSource.cloneWithRows(movies),
        loaded: true
      })
    })
    .done()
  },

  getLoadingView() {
    return (
      <View style={styles.container}>
        <Text>
          Loading Movies...
        </Text>
      </View>
    )
  },

  renderMovie(movie) {
    if (!this.state.loaded) {
      return this.getLoadingView()
    }

    return (
      <View style={styles.container}>
        <Image
          source={{uri: movie.posters.thumbnail}}
          style={styles.thumbnail}
        />
        <View style={styles.rightContainer}>
          <Text style={styles.title}>{movie.title}</Text>
          <Text style={styles.year}>{movie.year}</Text>
        </View>
      </View>
    )
  },

  render() {
    return (
      <ListView
        dataSource={this.state.dataSource}
        renderRow={this.renderMovie}
        style={styles.listView}
      />
    )
  }

}

AppRegistry.registerComponent('movieList', () => movieList)
/**
*示例React本机应用程序
* https://github.com/facebook/react-native
*/
"严格使用",;
var React=require('React-native'),
{
样式表,
组成部分,
评估学,
ListView,
看法
文本,
形象
}=反应,
baseUrl=http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json',
apiKey='7waqfqbprs7pajbz28mqf6vz',
pageLimit=25,
查询字符串='?apikey='+apikey+'&页面限制='+pageLimit,
url=baseUrl+queryString,
styles=样式表.create({
容器:{
弹性:1,
flexDirection:'行',
为内容辩护:“中心”,
对齐项目:“居中”,
背景颜色:“白色”,
},
rightContainer:{
弹性:1,
},
标题:{
marginBottom:8,
textAlign:“中心”
},
年份:{
尺寸:10,
textAlign:“中心”
},
缩略图:{
宽度:53,
身高:81
},
列表视图:{
paddingTop:20,
背景颜色:“黑色”
}
})
类movieList扩展组件{
getInitialState(){
返回{
数据源:新建ListView.dataSource({
行已更改:(行1,行2)=>行1!==行2
}),
加载:false
}
},
电影({
返回获取(url)
.then((response)=>response.json())
.然后((数据)=>data.movies)
},
componentDidMount(){
这个。fetchMovies()
.然后((电影)=>{
这是我的国家({
dataSource:this.state.dataSource.cloneWithRows(电影),
加载:正确
})
})
.完成
},
getLoadingView(){
返回(
正在加载电影。。。
)
},
renderMovie(电影){
如果(!this.state.loaded){
返回此参数。getLoadingView()
}
返回(
{movie.title}
{电影年}
)
},
render(){
返回(
)
}
}
AppRegistry.registerComponent('movieList',()=>movieList)

我做错了什么?

您将
构造视为一系列类似于逗号分隔的
var
函数表达式,但这不是
的工作方式。类中的方法定义更像是函数声明,您不会在它们后面加逗号,因为它们不是函数声明的一部分在
var
之后的一个大表达式的变量列表是

class movieList extends Component{

  getInitialState() {
    return {
      dataSource: new ListView.DataSource({
        rowHasChanged: (row1, row2) => row1 !== row2
      }),
      loaded: false
    }
  } // <=== No comma here

  fetchMovies() {
    // ...
  }

  // ...
}
类movieList扩展组件{
getInitialState(){
返回{
数据源:新建ListView.dataSource({
行已更改:(行1,行2)=>行1!==行2
}),
加载:false
}

}//以防万一,人们会产生错误的想法:
{….}=React
这是一个ES6解构任务,是的,它是有效的。你知道,@tldr,如果你更新了你的个人资料,使之成为“tldr”的完整定义,那就太好了根据城市词典。当阅读你的个人资料时,每个人都会意识到他们花了太多的时间阅读它。:D(@T.J.Crowder是的,我内心的JSLint还没有完全更新:)我知道玩咖啡脚本总有一天会有回报的