Revision history [back]

click to hide/show revision 1
initial version

answered 2019-01-07 10:57:34 +0800

cor3000 gravatar image cor3000

ZK Team

I am not fully sure why your scenario behaves non deterministic, I assume it has to do with the notify change "*". When using a ListModelList there's no need to replace the model, just clear and refill it (it will update the combobox content automatically), then things get a lot simpler and the problem didn't happen anymore.

e.g.: http://zkfiddle.org/sample/h20l03/71-reset-combobox-MVVM

Besides you don't to bind the property selectedSearchedOrg to selectedItem. The ListModelList will keep track of selections automatically for you. You can retrieve it by calling searchedOrgs.getSelection(). Keeping duplicate state can often lead to synchronization issues. Only relying on a single source makes cleanup much simpler.

see this updated example: http://zkfiddle.org/sample/h20l03/72-reset-combobox-MVVM

It takes advantage of ListModelList keeping track of the selection, and only if the selection is changed you can update your own model property, or decide to keep it. Another benefit is that you only expose getters to the UI, making it easier to reason about the data flow.

I am not fully sure why your scenario behaves non deterministic, I assume it has to do with the notify change "*". When using a ListModelList there's no need to replace the model, just clear and refill it (it will update the combobox content automatically), then things get a lot simpler and the problem didn't happen anymore.

e.g.: http://zkfiddle.org/sample/h20l03/71-reset-combobox-MVVM

Besides you don't need to bind the property selectedSearchedOrg to selectedItem. The ListModelList will keep track of selections automatically for you. You can retrieve it by calling searchedOrgs.getSelection(). Keeping duplicate state can often lead to synchronization issues. Only relying on a single source makes cleanup much simpler.

see this updated example: http://zkfiddle.org/sample/h20l03/72-reset-combobox-MVVM

It takes advantage of ListModelList keeping track of the selection, and only if the selection is changed you can update your own model property, or decide to keep it. Another benefit is that you only expose getters to the UI, making it easier to reason about the data flow.

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More