一个数组中的元素个数不定,并且不同的元素个数,元素的排列顺序不同
_getSortedEndpoints() {
const {device} = this.props;
let endpoints = device.endpoints;
if (endpoints.length === 2) {
return [endpoints[0], endpoints[1]];
} else if (endpoints.length === 3) {
return [endpoints[1], endpoints[2], endpoints[0]];
} else if (endpoints.length === 4) {
return [endpoints[0], endpoints[1], endpoints[2], endpoints[3]];
} else {
return endpoints;
}
}
_showButtonList() {
return (
<View style={styles.viewStyle}>
{this._getSortedEndpoints().map(item => this._renderSceneItem(item))}
</View>
);
}