How can I listen for changes to properties on objects inside a list, with polymer-dart?

前端 未结 1 947
囚心锁ツ
囚心锁ツ 2021-02-09 10:10

I have a list of objects (for example, people), and I dynamically add and remove from the list. I want to run a query across the list when a certain property changes on any item

相关标签:
1条回答
  • 2021-02-09 10:27

    Enter: ListPathObserver!

    Add this constructor:

      MyElement() {
        ListPathObserver observer = new ListPathObserver(people, 'signedAgreement');
        observer.changes.listen((_) => notifyProperty(this, const Symbol('signedCount')));
      }
    

    Here, observer will fire when any person in people has its signedAgreement property changed.

    Then, in the callback, we notify the observer system that it should go look at signedCount.

    0 讨论(0)
提交回复
热议问题