reactjs – React React路由器中的范围
发布时间:2020-12-15 05:07:17 所属栏目:百科 来源:网络整理
导读:我有一个范围问题.我可以在构造函数中调用console.log this.props.routeParams.key.但是当在构造函数之外,在filterList函数中,我得到错误“未捕获的TypeError:无法读取未定义的属性’道具’”.我的范围问题是什么?为什么它可以从构造函数中读取,而不是从fi
我有一个范围问题.我可以在构造函数中调用console.log this.props.routeParams.key.但是当在构造函数之外,在filterList函数中,我得到错误“未捕获的TypeError:无法读取未定义的属性’道具’”.我的范围问题是什么?为什么它可以从构造函数中读取,而不是从filterList函数中读取?
我正在使用React Router Flux React. import AltContainer from 'alt-container'; import React from 'react'; import { Link } from 'react-router'; import Blogger from './Blogger' import List from './List' const rootURL = 'https://incandescent-fire-6143.firebaseio.com/'; import BlogStore from '../stores/BlogStore' import BlogActions from '../actions/BlogActions'; export default class BlogShow extends React.Component { constructor(props) { super(props); {console.log(this.props.routeParams.key)} } filterList(key) { if (this.props.routeParams.key===key){ return Blogstore.state.blog } } render() { {Object.keys(BlogStore.state.blog).map(this.filterList)} } }
这是因为您的filterList函数未绑定到您的组件
将它绑定在构造函数中 constructor(props) { super(props); this.filterList = this.filterList.bind(this); } 你读到它here (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读