【发布时间】:2016-10-24 22:14:46
【问题描述】:
我想在课程数组为空时隐藏表格元素。我希望下面的代码可以工作,但事实并非如此。有任何想法吗?有问题的代码行是:
<table className="table" style={courses.length > 0 ? 'show' : 'display:none'}>
import React, {PropTypes} from 'react';
import CourseListRow from './CourseListRow';
const CourseList = ({courses, onDelete}) => {
return (
<table className="table" style={courses.length > 0 ? 'show' : 'display:none'}>
<thead>
<tr>
<th> </th>
<th>Title</th>
<th>Author</th>
<th>Category</th>
<th>Length</th>
</tr>
</thead>
<tbody>
{courses.map(course =>
<CourseListRow key={course.id} course={course} onDelete={onDelete}/>
)}
</tbody>
</table>
);
};
CourseList.propTypes = {
courses: PropTypes.array.isRequired
};
export default CourseList;
【问题讨论】:
-
如何在没有三元运算符的情况下将内联样式应用于反应组件?