因此,我正在尝试学习Redux。顺便说一句,很好的图书馆。
但是,我正在使用Polymer,并且有一个待办事项列表元素。在我的待办事项列表元素中,我有一个属性定义,
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操作的分派,并且在传递给上述订阅函数的函数中接收到更新,并且状态被更新。
在Polymer中阅读dom-repeat和list的文档时,似乎是完整更新,并且不支持列表的重新呈现,相反,文档中提到使用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是相同的数组,聚合物将不知道其含量已改变。通过这种方式,您可以创建新的阵列,从而聚合物将改变阵列。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句