簡體   English   中英

Lodash&React,無法訪問局部變量

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

我在lodash的反應中遇到問題。 我的渲染函數的開頭有以下代碼。 我從this.state獲得layout的值,然后在數組中的每個布局對象上,將static設置為boolean屬性isEdit的反函數。 但是,我已經嘗試了一切,由於某種原因,我無法在lodash函數中訪問isEdit。 這是未定義的...我無法弄清楚自己在做什么錯,因此我們將不勝感激。

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

您是說將布局上的所有靜態屬性都設置為true 嗎? B'cos

!undefined would be true

可以肯定的是,您也可以為isEdit prop設置defaultProp

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM