根據MDN「您也可以對每個案例執行多個單獨操作,並用逗號分隔它們。」下面的例子工程:React JSX中的條件渲染組件部分
var stop = false, age = 23;
age > 18 ? (
alert("1"),
alert("2")
) : (
stop = true,
alert("Sorry, you are much too young!")
);
但我似乎無法像在下面看到的那樣做React。我期望顯示「是」和「否」按鈕,但它只顯示「否」按鈕。
return (
<div className="topcoat-list">
<ul className="topcoat-list__container">
{
notes.map(function (note) {
var title = note.content.substring(0, note.content.indexOf("\n"));
title = title || note.content;
var toggleDeleteDialogs = this.state.isConfirming && note.id === notepad.selectedId;
var disableDelete = this.state.isConfirming && note.id !== notepad.selectedId;
return (
<li key={note.id} onClick={this.onSelectNote.bind(null, note.id)} className="topcoat-list__item">
{title}
{
toggleDeleteDialogs ?
(
<button key={note.id} onClick={this.deleteThisNote.bind(null, note.id)} className="half">Yes</button>,
<button className="half" onClick={this.onCancelDelete}>No</button>
) : (
<button key={note.id} onClick={this.deleteThisNote.bind(null, note.id)} className="full" disabled={disableDelete ? "disabled" : ""}>Delete Note</button>
)
}
</li>
);
}.bind(this))
}
</ul>
</div>
);
全部標記:https://jsfiddle.net/55fvpcLo/
是我的語法關閉或會這樣更優雅呢?
這工作的感謝。我之前遇到過這個問題,但這次我並沒有想到這一點。就像你說的,沒有錯誤產生。 – komplexb 2015-03-13 17:37:22