-
-
Notifications
You must be signed in to change notification settings - Fork 132
Closed
Labels
Description
I have a personal component for displaying a list of data ...
I use a slot for passing a custom template for lines
each line have a toggle button ... and i listent the 'change' event, if value change, send new value on my api and when api response, call a refresh for new data....
But the toggle isn't reactive ! i don't know why ...


i use this for refreshing my data :
refresh_data(dataRef, data) {
if (typeof dataRef !== 'undefined') {
_.each(data, (value, key) => {
if (key !== 'id') {
if (_.isObject(value) && !_.isArray(value)) {
this.refresh_data(dataRef[key], value);
} else {
this.$set(dataRef, key, value);
}
}
});
}
},
async refresh() {
this.isLoading = true;
const fn = this.$ajax[this.method];
await fn(this.uri, this.data, this.config).then((items) => {
if (items.length < this.items.length) {
const deletedData = _.differenceWith(this.items, items, (x, y) => x.id === y.id);
deletedData.forEach((data) => {
this.$delete(this.items, _.findIndex(this.items, data));
});
}
const updatedData = _.differenceObj(items, this.items, true);
updatedData.forEach((data) => {
const dataRef = this.items.find(x => x.id === data.id);
if (typeof dataRef !== 'undefined') {
this.refresh_data(dataRef, data);
} else {
this.$set(this.items, this.items.length, data);
}
});
this.isLoading = false;
this.init = true;
});
},
and in my render :
<template slot="tab-list-content" slot-scope="ctx">
<td class="check">
<toggle-button
:width="80"
:height="30"
:sync="true"
:value="ctx.item.item.check !== null"
:color="{checked: '#16a085', unchecked: '#e74c3c'}"
:labels="{checked: checkDate(ctx.item.item.check), unchecked: $t('form.pending')}"
@change="onChangeToggleCheck(ctx.item.item)"
></toggle-button>
</td>
<td v-if="!companySelected" class="site">{{ ctx.item.item.site_name }}</td>
<td class="task" :class="checkDeadline(ctx.item.item)">{{ ctx.item.item.text }}</td>
<td class="date" :class="checkDeadline(ctx.item.item)">{{ ctx.item.item.deadline | moment('Do MMMM') }} </td>
</template>
robmazur, eduard-vm, euvl and SimonSiefke