Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.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 (React Native)显示阵列中项目的卡片列表_Javascript_Reactjs_Mobile_Native - Fatal编程技术网

Javascript (React Native)显示阵列中项目的卡片列表

Javascript (React Native)显示阵列中项目的卡片列表,javascript,reactjs,mobile,native,Javascript,Reactjs,Mobile,Native,假设我有两个数组 词与定义 导出默认类字典扩展React.Component{ 建造师(道具){ 超级(道具); 此.state={ 字:[], 定义:[], 索引:0 }; }您可以使用函数。Array.prototype.map函数回调中的第二个参数是index。您可以使用该索引显示相应的定义项,如下所示 export default class Dictionary extends React.Component { constructor(props) { supe

假设我有两个数组 词与定义

导出默认类字典扩展React.Component{
建造师(道具){
超级(道具);
此.state={
字:[],
定义:[],
索引:0
};    
}
您可以使用函数。
Array.prototype.map
函数回调中的第二个参数是index。您可以使用该索引显示相应的
定义
项,如下所示

export default class Dictionary extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
        word: ["a","b","c"],
        definition:["a","b","c"],
        index: 0
    };    

    render() {
       <div>
       {this.state.word.map((w,i) => {
          return <Card word = {w} definition = {this.state.definition[i]}/> 
       })}
       </div>
    }
}
导出默认类字典扩展React.Component{
建造师(道具){
超级(道具);
此.state={
单词:[“a”、“b”、“c”],
定义:[“a”、“b”、“c”],
索引:0
};    
render(){
{this.state.word.map((w,i)=>{
回来
})}
}
}

在您所在的州,您可以将单词和定义合并为一种方式,如:

dictionary: [
  {
    index: 0,
    word: 'Car',
    definition: 'Definition of car',
  },
  // More objects like the one above
]
然后编写一个函数来呈现这个对象数组,可以如下所示:

renderDictionary() {
  return (this.state.dictionary.map(word => {
    <Card key={word.index} word={word.word} definition={word.definition} />
  }));
}
renderDictionary(){
return(this.state.dictionary.map)(word=>{
}));
}
然后调用函数:

export default class Dictionary extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      dictionary: [
        {
          index: 0,
          word: 'Car',
          definition: 'Definition of car',
        },
        // More objects like the one above.
      ],
    };
  }

  renderDictionary() {
    return (this.state.dictionary.map(word => {
      <Card key={word.index} word={word.word} definition={word.definition} />
    }));
  }

  render () {
    return (
      <View>
        {this.renderDictionary()}
      </View>
    );
  }
}
导出默认类字典扩展React.Component{
建造师(道具){
超级(道具);
此.state={
字典:[
{
索引:0,
“汽车”这个词,
定义:“汽车的定义”,
},
//更多类似上面的对象。
],
};
}
renderDictionary(){
return(this.state.dictionary.map)(word=>{
}));
}
渲染(){
返回(
{this.renderDictionary()}
);
}
}