ReactJs样式表行从props
ReactJs style table row from props
我试图样式我的tr的背景,如果一个道具是存在的:
我在我的一个专栏中传递prop:
<Column highlightRow="yes" />
这是我的表行渲染:
render: function () {
var columns = this.props.columns;
var data = this.props.data;
//loop through columns looking for prop
var styleCheck = columns.map(function (column) {
if (column.props.highlightRow) {
var styles = {
backgroundColor: 'pink'
};
}
});
return (
<tr style={styles}>
{this.getCellNodes()}
</tr>
);
}
我一直得到错误styles is not defined
有人能帮忙吗?
您只需要将styles
变量的作用域设置为可见:
render: function () {
var columns = this.props.columns;
var data = this.props.data;
var styles = {};
//loop through columns looking for prop
var styleCheck = columns.map(function (column) {
if (column.props.highlightRow) {
styles = {
backgroundColor: 'pink'
};
}
});
return (
<tr style={styles}>
{this.getCellNodes()}
</tr>
);
}
除此之外,目前highlightRow
设置为任意字符串都为真。
相关文章:
- 当包含另一个asp文件时,是否也包含所有引用的样式和脚本页面
- 将样式表插入iframe
- 跟踪在页面加载时应用内联样式的JavaScript
- 如果文本字段为空,则使用JavaScript应用CSS样式
- 定义完全独立的样式信息
- W3C循环样式的JavaScript
- jQuery/JavaScript在线公文包表单-打印样式表
- 使用递归、Ramda.js和无点样式重构字符串的getPermutations()
- FF和Chromium中CSS样式按钮的外观差异
- 如何首先设置样式<td>表中包含在窗体中的元素
- javascript问题正文样式
- 使用具有内联样式的tidy-html5
- DataTables-创建自定义分页样式(加载更多样式)
- 具有所有样式的文本正在复制到可编辑文本区域
- 如何提供在javascript中编写对对象的重复访问以设置元素样式的简写
- 绑定Range输入以修改样式
- 一个正则表达式,用于从JS中的HTML标记中删除id、样式和类属性
- 不同页面背景的body标记上的角度ng样式
- ReactJS:渲染不会根据 props 更改样式值
- ReactJs样式表行从props