聚合物不去除被删除的元素 [英] Polymer not removing deleted element
问题描述
使用Polymer Stater Kit,我创建了两个自定义元素:
Using the Polymer Stater Kit, I created two custom elements :
- flow-list.html 这里被声明为 flowElementArray )
- flow-element.html (这里定义了删除功能)
- flow-list.html (here is declared the flowElementArray)
- flow-element.html (here is defined the delete function)
在 app.js 文件中,我还定义了一个addElement函数。
In the app.js file, I also defined a addElement function.
我可以在 flowElementArray 中添加元素,并显示它们。
I can add elements to the flowElementArray, and they are displayed.
但是,当我从 flowElementArray中删除元素
BUT, when I remove elements from the flowElementArray, they are still displayed.
这是我如何得到以下结果:
Here is how I got the following result :
- 应用程序启动(预先加载2个项目)
- 我删除一个项目(项目保留在屏幕上)
- 我添加一个项目(该项目被添加,在删除的上方)
这个奇怪行为的来源可能是什么?
What could be the source of this weird behaviour ?
编辑我无法使这个例子在plunker / codepen.io / jsbin上运行,所以在github上。
Edit I couldn't make the example run on plunker/codepen.io/jsbin so here it is on github.
- GitHub回购: https://github.com/JeanReneRobin/octo
- GitHub页面: http://jeanrenerobin.github.io/octo/
- GitHub repo : https://github.com/JeanReneRobin/octo
- GitHub page : http://jeanrenerobin.github.io/octo/
我如何添加元素:
app.storageLoaded = function() {
if (this.$.s1.value === '' || this.$.s2.value === '') {
window.alert('One field is Empty!');
return;
}
this.$.flowListID.push('flowDictionnary',
{
first: this.$.s1.value,
last: this.$.s2.value
});
};
我如何删除:
removeItem: function() {
var counter = 0;
while (counter < this.dict.length) {
var item = this.dict[counter];
if (item.first === this.name) {
this.dict.splice(counter, 1);
} else {
counter++;
}
}
}
推荐答案
在Polymer中对数组属性进行操作时,需要使用 this.push('myArrayProperty',item)
,。在操作后,拼接('myArrayProperty',0,1)
或调用 this.notifyPath('myArrayProperty')
When doing operations on array properties in Polymer, you need to use the this.push('myArrayProperty', item)
, this.splice('myArrayProperty', 0, 1)
or call this.notifyPath('myArrayProperty')
after the operation.
removeItem: function() {
var counter = 0;
while (counter < this.dict.length) {
var item = this.dict[counter];
if (item.first === this.name) {
// this.dict.splice(counter, 1);
this.splice('dict', counter, 1);
} else {
counter++;
}
}
}
这篇关于聚合物不去除被删除的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!