【发布时间】:2017-01-12 06:55:32
【问题描述】:
我使用对象数组作为我的 ractive 组件(从 PouchDB 接收)的数据,该组件需要在 ractive 内部过滤以获得正确的输出。但是我尝试过的任何东西——即使被称为“文档”的数据被正确更改,过滤后的又名计算值保持不变。
我尝试了方法:
new Ractive({
el: '#container',
template: Listing,
magic: true,
modifyArrays: true,
data: {docs},
computed: {
List: function(){
let tempList = [];
for(var i = 0; i < docs.length; i++) {
if (docs[i].specificValue == otherValue) {
let newValue = docs[i];
tempList.push(newValue);
}
}
return tempList;
}
}
});
带有辅助对象
Ractive.defaults.data.helper = function () {
for (var i = 0; i < docs.length; i++) {
if (docs[i].specificValue == otherValue) {
return docs[i].whatever ;
}
}
}
new Ractive({
el: '#container',
template: '{{helper()}}',
magic: true,
modifyArrays: true,
data: {List: docs}
});
和Ractive computed property中描述的数据函数
但没有任何事情能按预期进行。当我直接使用文档时,绑定按预期工作。
PS:代码可能看起来有点别扭,因为我只是复制和简化。
【问题讨论】:
-
你能提供一个简单、可重现的演示吗?
标签: ractivejs