尝试在本机中更新JSON文件

时间:2017-01-19 23:20:14

标签: json react-native

我正在尝试使用react native来更新JSON文件中的布尔值的状态。我试图通过点击一个复选框来做到这一点,但我开始失去信心!

我还导入了JSON文件:

import quotes from './quotes.json';


_toggleCheck() {
        var checked = !this.state.checked;
        this.setState({ checked: checked });
        var j = JSON.parse(quotes);
        j.quotesArray.checked = checked;
          console.log('isBoxChecked' + checked); //
        this.props.onChange && this.props.onChange(this.props.name, checked);
    }

我收到此错误,不确定原因。

enter image description here

1 个答案:

答案 0 :(得分:0)

我渴望这么久的解决方案最终失败了

_toggleCheck() {
                var checked = !this.state.checked;
                this.setState({ checked: checked });
                quotes.quotesArray[0].isChecked = checked;
                console.log(quotes)
                this.props.onChange && this.props.onChange(this.props.name, checked);
            }