-1
這個jsx有什麼問題?意外的jxs使用括號和&&
return(
{(item.min_price > 0 || item.max_price > 0) &&
<div className="col-md-12">
{this.renderPrice()}
</div>}
);
我在第2行
這個jsx有什麼問題?意外的jxs使用括號和&&
return(
{(item.min_price > 0 || item.max_price > 0) &&
<div className="col-md-12">
{this.renderPrice()}
</div>}
);
我在第2行
得到了意外的標記如果您刪除curly brackets
它將工作。
const item = {
\t min_price: 10,
max_price: 10
}
class Test extends React.Component {
\t \t render(){
\t return(
(item.min_price > 0 || item.max_price > 0) &&
<div className="col-md-12">
<div>Price</div>
</div>
);
}
}
React.render(<Test />, document.getElementById('container'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react-dom.min.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
刪除大括號{} –
@OriDrori在哪裏? –
外面的'{}'在那裏是無效的(或者說他們的內容無效)。對象文字不能包含任意表達式。 '{... && ...}'簡直是無效的JavaScript。你可能會想:「'{...}'被用來在JSX中嵌入表達式」,這是真的。但外層的'{}'不在JSX內部。 –