Svelte doesn't detect the mutation of your options
object:(Svelte不会检测到您的options
对象的变异:)
options.push(option)
It only tracks assignments, with =
.(它仅使用=
跟踪分配。)
A very common solution to make the compiler aware of the modification is this kind of situation is self-assigment:(使编译器知道修改的一个非常常见的解决方案是这种情况是自辅助的:)
// you'd also have to make it a `let`, of course
options.push(option)
// this, Svelte will see!
options = options
You can call that a Sveltism.(您可以称其为天鹅绒主义。)
Reactivity will ensue, and your select's options should be updated immediately.(随之而来的是反应性,您选择的选项应立即更新。)
See details in this section of the tutorial.(请参阅教程本节中的详细信息。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…