I have a Polymer dom-repeat list where children are sorted ok by their initial value. When I change the value inside the child, the dependent sort order of the list is not updated. How can i achieve this?
<body>
<list-records></list-records>
<dom-module id="list-records">
<template>
<template is="dom-repeat"
items="{{records}}"
sort="sortByValue">
<single-record record="{{item}}"
base="{{base}}">
</single-record>
</template>
</template>
<script>
Polymer({
is: 'list-records',
properties: {
records: {
type: Array,
value: [
{number:1, value:4},
{number:2, value:2},
{number:3, value:3}]
}
},
sortByValue: function(a, b) {
if (a.value < b.value) return -1;
if (a.value > b.value) return 1;
return 0;
}
});
</script>
</dom-module>
<dom-module id="single-record">
<template>
<div>
Number: <span>{{record.number}}</span>
Value: <span>{{record.value}}</span>
<button on-tap="_add">+</button>
</div>
</template>
<script>
Polymer({
is: 'single-record',
properties: {
record: Object,
},
_add: function() {
this.set('record.value', this.record.value + 1);
}
});
</script>
</dom-module>
</body>
Reference Information. In an application based on real locations, I center (lat, lng) and get a list of keys for locations around the center. I create a child for each key. The child uses the key to get lat, lng information from the database (async). Using lat lng information from the center and from the location, I can calculate the distance inside the child. The list must be ordered by estimated distance.