2016-08-05 113 views
1

我需要给动态内嵌样式与静态默认样式风格。我该如何做到这一点动态inilne风格阵营本地

<View 
    style={[styles.card,{{width:width, height: height}}]}> 
      <View style={styles.card}> 
       <Text> 
        <Image 
        source={{uri: this.props.media.image_url}} 
        style={{width:width, height: this.props.media.height}}/> 
       </Text> 
      </View> 
</View> 

上面的代码不适合我。

+0

,如果你会去服务器渲染,你可能不得不改变未来的事情,因为风格加载器未通过服务器渲染 – abhirathore2006

+0

什么可以为服务器渲染解决方案支持? –

+0

使用https://github.com/webpack/extract-text-webpack-plugin这将结合在一个文件中的所有CSS。 – abhirathore2006

回答

2

不,这个问题是不是订单,你有没有通过动态(内联样式)正确。你额外花括号包裹其中

更改此:

style={[styles.card,{{width:width, height: height}}]} 

到:

style={[styles.card,{width:width, height: height}]} 

你实际上已经做了同样的事情在你的答案以上。

0

最后想了很多后,我能解决这个问题。 下面是代码

<View 
    <View style={[{width:width, height: height},styles.card]}> 
     <View style={styles.card}> 
      <Text> 
       <Image 
       source={{uri: this.props.media.image_url}} 
       style={{width:width, height: this.props.media.height}}/> 
      </Text> 
     </View> 
    </View> 
</View> 
+0

澄清解决方案:样式* do *的顺序很重要,它们从左到右应用,所以'styles.card'覆盖宽度和高度。 – Hanse