首页 > 解决方案 > 反应原生 - 无法在“CSSStyleDeclaration”上设置索引属性

问题描述

我想动态替换 css 变量,但得到以下错误 -

global.js

answerzerocontainer: {
        flex: .5,
        backgroundColor: '#fcba03',
        marginBottom:10,
        justifyContent: 'center',        
    },

测试.js

<View style={globalStyles.homepagecontainer}>
            <Text>{question}</Text>            
            {
                answers.map((a, key)=> {
                    key = 'zero'
                    const cssstyle = 'globalStyles.answer' + key + 'container'
                    console.log('style - ', cssstyle)
                    return (<View style={cssstyle}>
                                <Text>a</Text>
                            </View>)
                })
            }

错误 :-

Failed to set an indexed property on 'CSSStyleDeclaration'

标签: react-native

解决方案


你能把数字值也放在一对单引号“10”内吗?


推荐阅读