on supprime les 2 methodes Vue.set et Vue.delete, car vue3 les mutations

des array sont reactives.
Par contre, la methode findIndex semble ne pas fonctionner dans tous les
cas, pour palier j'ai creer une methode trouver_index. a tester
This commit is contained in:
Christophe 2020-10-19 21:05:00 +02:00
parent 33f1e32a8c
commit 34671bcf40
2 changed files with 29 additions and 11 deletions

View file

@ -137,6 +137,16 @@ function exporterCSV(json, delimitercsv, name) {
document.body.removeChild(link);
}
function trouver_index(table, id) {
let i = -1;
table.forEach((ligne, index) => {
if (ligne.html.id === parseInt(id)) {
i = index;
}
});
return i;
}
let monTableau = {
props: {
tparpage: {
@ -269,11 +279,12 @@ let monTableau = {
}
if (parseInt(id) > 0) {
if (data.length > 0) {
let i = this.table.findIndex((ligne) => ligne.html.id === parseInt(id));
let i = trouver_index(this.table, id);
this.table[i] = data[0];
} else {
let i = this.table.findIndex((ligne) => ligne.html.id === parseInt(id));
Vue.delete(this.table, i);
let i = trouver_index(this.table, id);
console.log('index ', i);
this.table.splice(i, 1);
}
} else {
this.table = data;

View file

@ -185,6 +185,16 @@ function exporterCSV(json, delimitercsv, name) {
document.body.removeChild(link);
}
function trouver_index(table, id) {
var i = -1;
table.forEach(function (ligne, index) {
if (ligne.html.id === parseInt(id)) {
i = index;
}
});
return i;
}
var monTableau = {
props: {
tparpage: {
@ -323,17 +333,14 @@ var monTableau = {
if (parseInt(id) > 0) {
if (data.length > 0) {
var i = _this2.table.findIndex(function (ligne) {
return ligne.html.id === parseInt(id);
});
var i = trouver_index(_this2.table, id);
_this2.table[i] = data[0];
} else {
var _i2 = _this2.table.findIndex(function (ligne) {
return ligne.html.id === parseInt(id);
});
var _i2 = trouver_index(_this2.table, id);
Vue.delete(_this2.table, _i2);
console.log('index ', _i2);
_this2.table.splice(_i2, 1);
}
} else {
_this2.table = data;