作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以,我正在尝试学习 Redux。顺便说一句,很棒的图书馆,真的很容易掌握。
但是,我使用的是 Polymer,并且有一个 todo-list 元素。在我的待办事项列表元素中,我有一个属性定义,
properties: {
items: {
type: Array,
notify: true
}
},
和一个准备好的函数,
ready: function() {
var that = this;
store.subscribe(function() {
var state = store.getState();
console.log('State have been updated ', state);
that.items = state.todos;
that.notifyPath('items', that.items);
console.log('items ', that.items);
});
store.dispatch(actions.requestTodos());
}
Redux 部分工作得很好。在另一个元素(不重要)中,我执行了 ADD_TODO 操作的分派(dispatch),我在传递给上面的订阅函数的函数中收到更新,并且状态被更新。
当阅读 dom-repeat 和 Polymer 列表的文档时,似乎不支持列表的完整更新和重新渲染,相反文档提到使用 pop、push 或 splice 等方法更新列表(大批)。但我真的不想那样。
关于如何使用新的完整状态更新列表的任何想法?因为现在,列表已更新但未重新呈现,因此不会显示更改。
最佳答案
ready: function() {
var that = this;
store.subscribe(function() {
var state = store.getState();
console.log('State have been updated ', state);
that.set('items',state.todos.slice());
console.log('items ', that.items);
});
store.dispatch(actions.requestTodos());
}
在列表上使用 slice()。你插入到 this.items state.todos
问题是如果 state.todo 是同一个数组 polymer 将不知道内容被改变了。通过这种方式,您可以创建新阵列,因此 polymer 现在将改变阵列。
关于javascript - 如何用新数组更新 dom-repeat 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35386033/
我是一名优秀的程序员,十分优秀!