我正在尝试将项目插入数组,但它没有出现在 HTML 中。
代码示例:
<script type="text/" id="tmpl">
<button on-click="create" type="button">Create</button>
{{#items}}{{.}},{{/items}}
</script>
<body>
<div id="container">
</div>
</body>
var model = {items: [1, 2, 3, 4]};
var ractive = new Ractive({
el: "#container",
template: "#tmpl",
data: model
});
ractive.on("create", function() {
model.items.push(7);
console.log(model.items);
});
https://codepen.io/anon/pen/eWzJNR
出了什么问题?
最佳答案
魔法模式和数组修改在 0.8 中默认关闭,并在 0.9 中等待删除(它们将通过适配器在外部完成)。
对于 0.8,您可以手动将 modifyArrays
配置设置为 true
。或者,只要您有对该实例的引用,只需使用注释中提到的 Ractive 内置数组方法就可以了。
关于javascript - 数组修改在 Ractive JS 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43552161/