Skip to content

Commit

Permalink
fix(location): fix the setState didn't work problem
Browse files Browse the repository at this point in the history
this problem caused because the father's state changed and it re-rendered, however, the son's
initial progress do not begin. Only the value of the data passed changed. The son re-rendered with
the old data.
  • Loading branch information
lulutia committed May 25, 2016
1 parent 40c8b20 commit 365d37a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 55 deletions.
78 changes: 39 additions & 39 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions app/csetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ class CPicker extends Component {
passData.length = 1;
let secondValue = choseValue[0];
passData.push(Object.keys(this.props.data[secondValue]));
// let thirdValue = Object.keys(this.props.data[secondValue])[0];
// passData.push(this.props.data[secondValue][thirdValue]);
this.setState({passData:passData});
this.forceUpdate();
let thirdValue = Object.keys(this.props.data[secondValue])[0];
passData.push(this.props.data[secondValue][thirdValue]);
this.setState({passData:passData}, () =>{
this.forceUpdate();
});

}
render(){

Expand Down Expand Up @@ -146,7 +148,6 @@ class CPicker extends Component {
</View>
<View style={[styles.pickContainer, this.state.selfStyle]} >
{this.state.passData.map((item,index) =>{
console.log(this.state.passData);
return(
<CPickroll
key = {index}
Expand All @@ -160,13 +161,7 @@ class CPicker extends Component {
itemCount = {this.props.data.length}
onValueChange={this._changeLayout.bind(this)}
>
{this.state.passData[index].map((carMake) => (
<PickerItem
key={carMake}
value={carMake}
label={carMake}
/>
))}

</CPickroll>)})}
</View>

Expand Down
9 changes: 5 additions & 4 deletions app/roll2.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CPickroll extends Component {
if(newProps.getValue!==this.props.getValue&&newProps.getValue===true){
this.props.handleValue(this.state.items[this.index].label,this.index);
}
this.setState(this._stateFromProps(newProps));
}

_stateFromProps(props){
Expand All @@ -42,10 +43,10 @@ class CPickroll extends Component {
let pickerStyle = props.pickerStyle;
let itemStyle = props.itemStyle;
let onValueChange = props.onValueChange;
React.Children.forEach(props.children, (child, index) => {
child.props.value === props.selectedValue && ( selectedIndex = index );
items.push({value: child.props.value, label: child.props.label});
});
this.props.data.map((child,index) =>{
child === props.selectedValue && ( selectedIndex = index );
items.push({value: child, label: child});
})
return {
selectedIndex,
items,
Expand Down

0 comments on commit 365d37a

Please sign in to comment.