I am trying to get different configs with the same ID to mirror each other through el-switches. What I will type below is only a portion of the template and script but I will happily provide more context if needed. The code I have right now is as follows:
<el-switch v-else-if="item.Type == 'bool'"
class="float-left margin-top-8"
v-model="item.Value[UserSelected.Instance]"
:id="item.Id"
:ref="item.Id"
:disabled="item.disabled"
:active-value="1"
:inactive-value="0"
@change="ModifiedSet(index, UserSelected.Instance, item.Id)"
ModifiedSet: function(indexOnPage, inst, id) {
this.PageDisplay[indexOnPage].Modified.splice(inst, 1, true);
this.UserSelected.Uid = id;
// Find items with duplicate IDs
let duplicateIds = this.findDuplicateIds(Object.values(this.UidItemList));
// Sync values for duplicate IDs
if (duplicateIds.includes(id)) {
this.syncDuplicateValues(id);
}
// Scan for UID Value modifications
this.CountModified();
},
syncDuplicateValues: function(duplicateId) {
let items = Object.values(this.UidItemList);
let duplicateItems = items.filter(item => item.Id === duplicateId);
let valueToSync = duplicateItems[0].Value[this.UserSelected.Instance];
// Sync value for all duplicate items
duplicateItems.forEach(item => {
item.Value[this.UserSelected.Instance] = valueToSync;
});
},
findDuplicateIds: function(items) {
let idCount = {};
items.forEach(item => {
let id = item.Id;
idCount[id] = (idCount[id] || 0) + 1;
});
let duplicateIds = [];
for (let id in idCount) {
if (idCount[id] > 1) {
duplicateIds.push(id);
}
}
return duplicateIds;
},
/>```
The code nearly works, all switches that are not duplicates change as normal, however when a switch with a duplicate Id is changed only the first instance of the item.id value changes. I can change all duplicate switches by using the first switch but none of the switches that are not the first instance will change when I press them. I have tried changing the v-model, watchers, completely different methods and this was the closest I could get but am still missing something. Any help is good help.
New contributor
Harrison Hodge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.