react双组件传值和传参
<!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双组件传值和传参的更多相关文章
- react事件绑定,事件传参,input单向数据绑定
import React, { Component } from 'react'; class New extends Component { constructor(props){ super(pr ...
- vue 和 react 路由跳转和传参
react 1 .跳转方式加传参 this.props.history.push({ //地址 pathname: '/film/Details', //路由传参 ...
- 从 Vue 的视角学 React(四)—— 组件传参
组件化开发的时候,参数传递是非常关键的环节 哪些参数放在组件内部管理,哪些参数由父组件传入,哪些状态需要反馈给父组件,都需要在设计组件的时候想清楚 但实现这些交互的基础,是明白组件之间参数传递的方式, ...
- pentaho cde 封装自定义图形控件,动态传参
在实际项目中经常会用到将经常用到的图形表格组成一个控件,其他地方直接调用,类似于服务器开发的接口,而现在就需要将一些常用的图形做封装,这样就不必重复多次创建相同的内容. 下面就简单的定义一个自定义柱形 ...
- React中使用 react-router-dom 路由传参的三种方式详解【含V5.x、V6.x】!!!
路由传值的三种方式(v5.x) params参数 //路由链接(携带参数): <Link to='/demo/test/tom/18'}>详情</Link> //或 <L ...
- React browserHistory.push()传参
1.browserHistory.push({ "pathname":'/interface_log', state: ...
- vue-router中query和params传参(接收参数)以及$router、$route的区别
query传参: this.$router.push({ path:'/...' query:{ id:id } }) 接收参数:this.$route.query.id params传值: 传参: ...
- react router路由传参
今天,我们要讨论的是react router中Link传值的三种表现形式.分别为通过通配符传参.query传参和state传参. ps:进入正题前,先说明一下,以下的所有内容都是在react-rout ...
- react 路由传参
今天,我们要讨论的是react router中Link传值的三种表现形式.分别为通过通配符传参.query传参和state传参. ps:进入正题前,先说明一下,以下的所有内容都是在react-rout ...
随机推荐
- rem实现自适应
总结一下,rem实现自适应:用rem代替px,配合媒体查询设置font-size:n%. 首先,px是死的.若一律用px,那就会大的显得小,小的屏幕显得大.其次,rem是活的,通过设置字体大小可以引起 ...
- MySQL高级知识(七)——索引面试题分析
前言:该篇随笔通过一些案例,对索引相关的面试题进行分析. 0.准备 #1.创建test表(测试表). drop table if exists test; create table test( id ...
- UVA437-The Tower of Babylon(动态规划基础)
Problem UVA437-The Tower of Babylon Accept: 3648 Submit: 12532Time Limit: 3000 mSec Problem Descrip ...
- tensorflow中的batch_normalization实现
tensorflow中实现batch_normalization的函数主要有两个: 1)tf.nn.moments 2)tf.nn.batch_normalization tf.nn.moments主 ...
- 一步一步和我学Apache JMeter
一. Apache JMeter介绍 1. Apache JMeter是什么? Apache JMeter 是Apache组织的开放源代码项目,是一个100%纯Java桌面应用,用于压力测试和性能测量 ...
- 后端list集合中的数据传递到前台HTML中显示(表格形式)
关键字:web项目中前后台数据传递问题 在学习web项目的过程中,我们肯定会遇到前后台数据交换问题.这个问题我也思考了很久,今天借此总结一下.由于博主水平有限,如有不当之处,还请大家多多指正,,废话不 ...
- 原生js 函数 callee属性
一.在es5中,函数中有arguments参数,该参数是一个包含函数传入的参数的类数组. <script> function myArrgu(x){ console.log(argumen ...
- # 20175329 2018-2019-2 《Java程序设计》第二周学习总结
# 学号 2018-2019-3<Java程序设计>第三周学习总结 ## 教材学习内容总结 第二三章与我们所学习的C语言有很多的相似点,在这里我想主要就以我所学习的效果来讨论一下JAVA与 ...
- 建一个网站python
域名()+ 服务器+ 源码 制作一个自己的网站.................
- WindowsFormsHost下MouseWheel失效的解决办法
原文:WindowsFormsHost下MouseWheel失效的解决办法 看了网上有些写的用钩子,但是,在Stack Overflow上找到一个简便的方式