【发布时间】:2018-05-04 09:56:05
【问题描述】:
我正在使用 Polymer js 创建一个非常简单的 CRUD 应用程序,但在编辑记录时遇到了一些问题。
这是添加/编辑的代码:
_addTodo() {
if(this.user.id) {
let foundIndex = this.users.findIndex( x => x.id === this.user.id);
this.users[foundIndex] = this.user;
this.set('users', this.users);
console.log(this.users);
}
else {
this.user.id = Math.floor((Math.random() * 100000) + 1);
this.push('users', this.user);
}
this.user = {};
}
虽然我可以看到用户对象中的值在浏览器控制台中发生了变化,但在 DOM/UI 中并没有发生变化。
如果我使用像下面这样的静态用户对象,那么它可以工作:
_addTodo() {
if(this.user.id) {
var users = [
{
id: 1,
name: 'xyz',
age: 21
},
{
id: 2,
name: 'xyz123',
age: 5
}
]
this.set('users', users);
console.log(this.users);
}
else {
this.user.id = Math.floor((Math.random() * 100000) + 1);
this.push('users', this.user);
}
this.user = {};
}
即使我使用了“notifyPath”而不是“set”,但这也不起作用。
谁能建议我在这里做错了什么,用户对象在 DOM 中没有改变?
更新:
如下所示,我正在使用 splice 来更新数组,但仍然无法正常工作。
【问题讨论】:
标签: polymer polymer-2.x