意外令牌使用函数内的函数进行反应

时间:2017-03-13 11:50:40

标签: javascript reactjs

下面的函数在我的渲染函数之上,有什么不对吗?它似乎不允许我把功能放在功能中。

onSelected(i){

    this.state.active = [];
    this.state.active[i] = true;

    generateRangeFromIndex(index,steps=20){
        return [index*steps, index*steps+steps]
    }

    this.setState({
        active: this.state.active,
        showHandler: true,
        selectedRange: generateRangeFromIndex(i)
    });

}

1 个答案:

答案 0 :(得分:0)

onSelected(i){

    this.state.active = [];
    this.state.active[i] = true;

    let t  = this; 

    this.setState({
        active: this.state.active,
        showHandler: true,
        selectedRange: t.generateRangeFromIndex(i)
    });

}
generateRangeFromIndex(index,steps=20){
    return [index*steps, index*steps+steps]
}