条件付きレンダリングに問題があります。これが私の100%の作業ビューです:
function todoItem(todo) {
return li('.list-item',[
todo.editing ? input('.todo-edit', {type: 'text', value: todo.text, autofocus: true, attributes: { 'data-id': todo.id }}) : '',
!todo.editing ? span(`.todo ${todo.completed ? '.completed' : ''}`, { attributes: { 'data-id': todo.id }}, todo.text) : '',
button('.remove-todo', {type: 'button', value: todo.id}, 'remove'),
todo.completed ? button('.unmark-todo', {type: 'button', value: todo.id}, 'unmark') : '',
!todo.completed ? button('.mark-todo', {type: 'button', value: todo.id}, 'mark as done') : ''
]);
const view = (state$) => {
return state$.map(todos =>
div([
input('.todo-input', {type: 'text', placeholder: 'Todo', value: ''}),
ul(todos.items.map(todo => todoItem(todo))),
footer(todos)
])
);
};
問題は、条件付きボタンを 2 つの個別の条件ではなく if-else に変更しようとしたときです。
todo.completed ?
button('.unmark-todo', {type: 'button', value: todo.id}, 'unmark') :
button('.mark-todo', {type: 'button', value: todo.id}, 'mark as done')
ボタンを「マーク解除」に切り替えてから、再び「マーク」に戻すようです(コンソールログで確認しました)。私のインテントは.markと.unmarkの 2 つのクラスにマップされているので、それは問題ではないと思います...
それは実際のエラーですか、それとも何か不足していますか?