我需要遍历一个类似数组的对象,并根据其长度在React Native中渲染组件,并且其中的和是代码:
const Screen = function({navigation, route}) {
var data = [];
var cases = [];
axios.get(`${uri}cases`)
.then(json => {
console.log(json)
data = json.data
}).catch(err => {
console.log(err)
});
function showCases(cases){
cases.forEach(one => {
cases.push(<Text>one._id</Text>)
})
}
showCases(data)
var comp = [<Text>Hello</Text>, <Text>Hello</Text>]
return(
<View>
<View>
<Button title='Click' onPress={() => {
cases.push(<Text>Hello</Text>)
console.log(cases)
console.log(comp)
console.log(comp == cases)
}} />
<Button
title="Modern Clinic"
disabled={true}
/>
<Button title="Profit" onPress={() => {
navigation.push('Profit')
}} />
<Button title="Expenses" onPress={() => {
navigation.push('Expenses')
}}/>
<Button title="New" onPress={() => {
navigation.push('New...')
}}/>
</View>
<SafeAreaView>
<ScrollView>
<Text>{cases}</Text>
</ScrollView>
</SafeAreaView>
</View>
)
}
我只想遍历data
变量和渲染组件我只想要逻辑,因此渲染<Text />
组件就可以了,只要逻辑就可以了
答案 0 :(得分:0)
您需要使用with open(os.devnull, 'wb') as f:
proc = subprocess.Popen(["tar", "-czvf", '/folder/archive.tar.gz', '/folder/some_other_folder'],
stdout=f, stderr=subprocess.PIPE)
_, stderr = proc.communicate()
if proc.returncode != 0:
# Assumes from __future__ import print_function at top of file
# because Python 2 print statements are terrible
print("tar exited with exit status {}:".format(proc.returncode), stderr, file=sys.stderr)
,它是React中最常用的组件来显示FlatList
,就像List
。
在参数数据中传递数据。并将您的组件放在Foreach
中。在您的组件中,用renderItem
访问foreach
的值,在此示例中,数据为:
{item.Something}
this.state.listParam = {.{"des":"Name","value":"John","mandatory":true, ...} }