简体   繁体   English

Lodash&React,无法访问局部变量

[英]Lodash & React, Unable to access local variables

I'm having an issue with lodash in react. 我在lodash的反应中遇到问题。 I've got the following code at the beginning of my render function. 我的渲染函数的开头有以下代码。 I get the value of layout from this.state & then on each layout object in the array, I set static as the inverse of the boolean property isEdit. 我从this.state获得layout的值,然后在数组中的每个布局对象上,将static设置为boolean属性isEdit的反函数。 However, I've tried everything and for some reason, I cannot access isEdit within my lodash function. 但是,我已经尝试了一切,由于某种原因,我无法在lodash函数中访问isEdit。 It's undefined... I cannot figure out what I'm doing wrong, so any help would be appreciated. 这是未定义的...我无法弄清楚自己在做什么错,因此我们将不胜感激。

public render() {
   const { isEdit, size } = this.props;
   const layout = this.state.layout.slice();
   _.forEach(layout, (x) => {
     x.static = !isEdit;
   });
   .....

Do you mean, all static property on layout are set to be true ? 您是说将布局上的所有静态属性都设置为true 吗? B'cos B'cos

!undefined would be true . !undefined would be true

Also can you set defaultProp for your isEdit prop, just to be sure. 可以肯定的是,您也可以为isEdit prop设置defaultProp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM