html文件中有一段代码:
{{#each answer in question.answers}}
<div id="answer-option-wrapper-{{randomId}}" class="col-md-12 question-answer-option--wrapper">
<div class="col-md-12 question-answer-option">
<input class="col-md-1" style="margin-top: 0.5em;" name="answer" type="{{radioOrCheckbox question}}">
<input id="{{randomId}}" type="text" placeholder="Вариант ответа" class="col-md-10 question-field-answer" style="" value="{{answer}}">
<div class="col-md-1 delete-answer-option" style=""><i style="padding:2px"
class="btn btn-danger fa fa-trash"
aria-hidden="true"></i></div>
</div>
</div>
{{/each}}
我使用 id 以防万一。question.answers
是一个数组。有一个处理程序change .question-field-answer
可以更新数据库中的这个值。不直接修改 DOM。
问题是在相同的值的answers
情况下,如果您更改输入中的文本,该文本会出现在相邻的输入中。有时从上面,有时从下面。在mongo
集合本身中,所有内容通常都会更新。我怀疑它meteor
使用字符串值作为键(为什么不使用数组中的索引?)。