<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="../node_modules/react/umd/react.development.js"></script>
<script src="../node_modules/react-dom/umd/react-dom.development.js"></script>
<script src="../node_modules/babel-standalone/babel.js"></script>
</head>
<body>
<div id="app"></div>
<script src="./db.js"></script>
<script type="text/babel">
class Item extends React.Component{
constructor(props){
super(props);
};
render(){
let {it}=this.props;
return(
<div>
{it.map((item,index)=>{//遍历拿到key值
return <div key={item.id}>
{Object.keys(item)}: //拿到数组
{Object.keys(item).map((v,ind)=>{
return <div key={ind}>
{item[v]} //遍历进行解析内置的json内容
</div>
})}
</div>
})}
</div>
)
}
}
class List extends React.Component{
constructor(props){
super(props);
};
render(){
let {users,companies} = this.props;
let arr = Object.keys(this.props); //拿到json的key值数组
return (
<div>
{ Object.keys(this.props)} //遍历传过来的json数据
{arr.map((item,ind)=>{ //遍历进行解析 拿到数组
return <Item key={ind} it={this.props[item]}/>
})}
</div>
)
}
}
class App extends React.Component{
constructor(props){
super(props);
this.state = {
data
}
};
render(){
return (
<div>
<List users={data.users}/> //将数组分组传过去
<List companies={data.companies}/>
</div>
)
}
}
ReactDOM.render(
<App/>,
document.getElementById('app')
)
</script>
</body>
</html>

react双组件传值和传参的更多相关文章

  1. react事件绑定,事件传参,input单向数据绑定

    import React, { Component } from 'react'; class New extends Component { constructor(props){ super(pr ...

  2. vue 和 react 路由跳转和传参

                      react  1 .跳转方式加传参 this.props.history.push({ //地址 pathname: '/film/Details', //路由传参 ...

  3. 从 Vue 的视角学 React(四)—— 组件传参

    组件化开发的时候,参数传递是非常关键的环节 哪些参数放在组件内部管理,哪些参数由父组件传入,哪些状态需要反馈给父组件,都需要在设计组件的时候想清楚 但实现这些交互的基础,是明白组件之间参数传递的方式, ...

  4. pentaho cde 封装自定义图形控件,动态传参

    在实际项目中经常会用到将经常用到的图形表格组成一个控件,其他地方直接调用,类似于服务器开发的接口,而现在就需要将一些常用的图形做封装,这样就不必重复多次创建相同的内容. 下面就简单的定义一个自定义柱形 ...

  5. React中使用 react-router-dom 路由传参的三种方式详解【含V5.x、V6.x】!!!

    路由传值的三种方式(v5.x) params参数 //路由链接(携带参数): <Link to='/demo/test/tom/18'}>详情</Link> //或 <L ...

  6. React browserHistory.push()传参

    1.browserHistory.push({                "pathname":'/interface_log',                state: ...

  7. vue-router中query和params传参(接收参数)以及$router、$route的区别

    query传参: this.$router.push({ path:'/...' query:{ id:id } }) 接收参数:this.$route.query.id params传值: 传参: ...

  8. react router路由传参

    今天,我们要讨论的是react router中Link传值的三种表现形式.分别为通过通配符传参.query传参和state传参. ps:进入正题前,先说明一下,以下的所有内容都是在react-rout ...

  9. react 路由传参

    今天,我们要讨论的是react router中Link传值的三种表现形式.分别为通过通配符传参.query传参和state传参. ps:进入正题前,先说明一下,以下的所有内容都是在react-rout ...

随机推荐

  1. Mac各种数据库安装和启动【笔记】

    MongoBD 一个基于分布式文件存储的数据库. 下载 https://www.mongodb.com/download-center#community 安装 解压包 mongodb 数据默认存在/ ...

  2. 在win10 64位系统安装 lxml (Python 3.5)

    本想直接用pip install lxml 命令安装完事,但是由于安装过程中跟VS的一些东西冲突怎么都安装不上,搜索到以下方法,问题解决. 步骤: 1.下载跟python匹配的.whl 文件(lxml ...

  3. JavaScript判断数据类型的方法

    typeof操作符 typeof 操作符作用:是用来检测变量的数据类型.对于值或变量使用 typeof 操作符会返回如下字符串. 数据类型undefined的判断示例 变量定义了但未初始化,就是und ...

  4. 数位dp D - Count The Bits

    题目:D - Count The Bits 博客 #include <cstdio> #include <cstring> #include <cstdlib> # ...

  5. 转://如何创建ASM磁盘

    1  前言 无论是安装单机版的asm还是rac都离不开ASM磁盘组的创建,创建ASM磁盘组的关键是创建好需要的asm磁盘,发现很多网友安装grid软件和grid实例,都在磁盘的创建这里有很大的问题,本 ...

  6. iptables 从一台机到另一台机端口转发

    启用网卡转发功能#echo 1 > /proc/sys/net/ipv4/ip_forward 举例:从192.168.0.132:21521(新端口)访问192.168.0.211:1521端 ...

  7. 90道Python面试题,做对80%直击年薪40w

    转发链接: 1.一行代码实现1--100之和 利用sum()函数求和 2.如何在一个函数内部修改全局变量 函数内部global声明 修改全局变量 3.列出5个python标准库 os:提供了不少与操作 ...

  8. camke使用例程

    1 同文件夹直接编译 1 同文件夹直接编译 # cmake needs this line cmake_minimum_required(VERSION 2.8) # Define project n ...

  9. ESP8266 mDNS

    https://circuits4you.com/2017/12/31/esp8266-mdns/ 本教程介绍如何使用ESP8266进行多播DNS?在网络世界中,很难记住每个网站和计算机的IP地址,解 ...

  10. docker 3 docker安装

    centos docker安装 docker支持以下centos版本: centos 7 (64-bit) centos 6.5 (64-bit)或更高的版本 前提条件 目前,centos仅发行版中的 ...