【发布时间】:2015-06-30 20:19:32
【问题描述】:
参考:http://jsfiddle.net/ffmqd0zz/
html:
<div id='books_container'/>
<script type='ractive/template' id="books">
{{#books}}
<div decorator='decoration' id="{{id}}">
<span> title: {{ title }}</span>
<span> id: {{ id }}</span>
</div>
{{/books}}
</script>
javascript:
var MyDecorator = function(node) {
console.log("init MyDecorator for id: " + $(node).attr('id'));
return { teardown: function() {}};
};
var books = new Ractive({
el: '#books_container',
template: '#books',
data: {books: [{"id": 1174,"title": "franny and zoey"},
{"id": 1175,"title": "moby duck"}]},
decorators: { decoration: MyDecorator }
});
console.log("init complete")
books.set('books', [{"id": 1176,"title": "life, the universe and stuff"},
{"id": 1177,"title": "yellowbrick road"},
{"id": 1178,"title": "grapes of wrath"} ]);
注意装饰器初始化记录到控制台。
当 Ractive 初始化时,“books”列表中的两个初始项目被正确修饰,如 console.log 消息所示。但是,当使用“books.set()”更改列表时,Ractive 只会装饰列表中的第三项,并且不会初始化 id 为 1176 和 1177 的书籍的装饰器。
它似乎通过在第三个添加的项目上初始化装饰器来优化性能,跳过前两个,即使它们已被替换。
是我做错了,还是这是一个错误?请有人提出解决方法。
提前致谢
【问题讨论】:
标签: ractivejs