Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 分段控制强制更新_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 分段控制强制更新

Javascript 分段控制强制更新,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我使用native的SegmentedControlIOS组件在三个值之间进行选择,到目前为止,这三个值运行良好。但是,当我的应用程序加载数据时,我希望确保用户不能更改与该控件关联的值,因为这将导致并发问题并中断更新 因此,我决定处理控件值更改的方法仅在加载过程当前未激活时调用通过属性提供的回调。否则,我调用this.forceUpdate(),以重新加载主机组件,其中包括设置分段控件的selectedIndex属性。但是,当调用this.forceUpdate时,所选索引不会更改。因此,我决定

我使用native的SegmentedControlIOS组件在三个值之间进行选择,到目前为止,这三个值运行良好。但是,当我的应用程序加载数据时,我希望确保用户不能更改与该控件关联的值,因为这将导致并发问题并中断更新

因此,我决定处理控件值更改的方法仅在加载过程当前未激活时调用通过属性提供的回调。否则,我调用
this.forceUpdate()
,以重新加载主机组件,其中包括设置分段控件的
selectedIndex
属性。但是,当调用
this.forceUpdate
时,所选索引不会更改。因此,我决定打印值
selectedIndex
设置为始终显示初始(希望的)索引

下面您可以看到my
rendering
方法用于显示分段控件的代码:

render: function()
{
    ...
    var indexBluetoothAutostart = 0;
    switch (this.props.data.BluetoothAutostartState)
    {
        case BluetoothAutostartState.OFF:
            indexBluetoothAutostart = 1;
            break;
        case BluetoothAutostartState.ON:
            indexBluetoothAutostart = 2;
            break;
        case BluetoothAutostartState.AUTO:
            indexBluetoothAutostart = 0;
            break;
    }
    console.log("index: " + indexBluetoothAutostart);
    ...
    return (
        ...
        <SegmentedControlIOS selectedIndex={indexBluetoothAutostart}
            momentary={false}
            onValueChange={(newValue) => this.changeBluetoothAutostartState(newValue)}
            values={[Localization.HomeFragment.BluetoothAutostartState.btnAuto, Localization.HomeFragment.BluetoothAutostartState.btnOff, Localization.HomeFragment.BluetoothAutostartState.btnOn]}/>
    );
}

谢谢你的帮助。提前感谢。

我只是在类的状态中添加了一个用'Date.now()'初始化的时间戳变量,而不是调用'this.forceUpdate',我更新了状态的时间戳:

this.setState({ timestamp: Date.now() });
this.setState({ timestamp: Date.now() });