knockoutjs ObservableArrays and sort function: UI is not updated

ε祈祈猫儿з 提交于 2019-12-03 14:40:31

You're unwrapping observable array when you are going to sort it. This is causes problem, because KO can't track array was changed. ko.observableArray() has sort function with same signature and it will notify observable's subscribers that it has been changed. Solution is very simple: remove braces vm.searchResults().sort => vm.searchResults.sort. Checkout my example: http://jsfiddle.net/RbX86/

Another way to tell KO that array has changes - call valueHasMutated method after manipulations with array. Please review this sample: http://jsfiddle.net/RbX86/1/ This approach is very good when you need to make many changes in your array and you want to refresh UI only one time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!