Существует узел с именем читательских рангов, имеющий 14 рангов, когда я пытаюсь вычислить точки с помощью кода c, он работает нормально, вот код для этого
rank_r = getReaderRank(parseFloat(oldPointsOfReder));
userDataReaderRef.update(rank_r);
function getReaderRank(points) {
let obj = {};
if (points >= 0 && points <= 50) {
obj.userRankBadge = 'Bronze';
obj.userRank = 'rank1';
obj.userPoints = points.toFixed(2);
obj.commission = 25;
obj.userRankPrice = 0.49;
} else if (points >= 51 && points <= 100) {
obj.userRankBadge = 'Silver';
obj.userRank = 'rank2';
obj.userPoints = points.toFixed(2);
obj.commission = 30;
obj.userRankPrice = 0.99;
} else if (points >= 101 && points <= 200) {
obj.userRankBadge = 'Gold';
obj.userRank = 'rank3';
obj.userPoints = points.toFixed(2);
obj.commission = 35;
obj.userRankPrice = 1.49;
} else if (points >= 201 && points <= 400) {
obj.userRankBadge = 'Platinum';
obj.userRank = 'rank4';
obj.userPoints = points.toFixed(2);
obj.commission = 40;
obj.userRankPrice = 1.99;
} else if (points >= 401 && points <= 800) {
obj.userRankBadge = 'Diamond';
obj.userRank = 'rank5';
obj.userPoints = points.toFixed(2);
obj.commission = 45;
obj.userRankPrice = 2.49;
} else if (points >= 801 && points <= 1600) {
obj.userRankBadge = 'Master';
obj.userRank = 'rank6';
obj.userPoints = points.toFixed(2);
obj.commission = 50;
obj.userRankPrice = 2.99;
} else if (points >= 1601 && points <= 3200) {
obj.userRankBadge = 'Challenger';
obj.userRank = 'rank7';
obj.userPoints = points.toFixed(2);
obj.commission = 55;
obj.userRankPrice = 3.49;
} else if (points >= 3201 && points <= 6400) {
obj.userRankBadge = 'Herald';
obj.userRank = 'rank8';
obj.userPoints = points.toFixed(2);
obj.commission = 60;
obj.userRankPrice = 3.99;
} else if (points >= 6401 && points <= 12800) {
obj.userRankBadge = 'Guardian';
obj.userRank = 'rank9';
obj.userPoints = points.toFixed(2);
obj.commission = 65;
obj.userRankPrice = 4.49;
} else if (points >= 12801 && points <= 25600) {
obj.userRankBadge = 'Crusader';
obj.userRank = 'rank10';
obj.userPoints = points.toFixed(2);
obj.commission = 70;
obj.userRankPrice = 4.99;
} else if (points >= 256001 && points <= 51200) {
obj.userRankBadge = 'Archon';
obj.userRank = 'rank11';
obj.userPoints = points.toFixed(2);
obj.commission = 75;
obj.userRankPrice = 5.49;
} else if (points >= 512001 && points <= 100000) {
obj.userRankBadge = 'Legend';
obj.userRank = 'rank12';
obj.userPoints = points.toFixed(2);
obj.commission = 80;
obj.userRankPrice = 5.99;
} else if (points >= 100001 && points <= 150000) {
obj.userRankBadge = 'Ancient';
obj.userRank = 'rank13';
obj.userPoints = points.toFixed(2);
obj.commission = 85;
obj.userRankPrice = 7.99;
} else if (points >= 150001 && points <= 10000000000) {
obj.userRankBadge = 'Archon';
obj.userRank = 'rank14';
obj.userPoints = points.toFixed(2);
obj.commission = 90;
obj.userRankPrice = 9.99;
} else if (points >= 10000000000) {
obj.userRankBadge = 'Archon';
obj.userRank = 'rank14';
obj.userPoints = points.toFixed(2);
obj.commission = 90;
obj.userRankPrice = 9.99;
} else {
obj.userRankBadge = 'Bronze';
obj.userRank = 'rank1';
obj.userPoints = '0';
obj.commission = 25;
obj.userRankPrice = 0.49;
}
return obj;
}
Но когда я я пытаюсь сделать его динамическим c для получения всех значений из базы данных firebase, следующая функция устанавливает все значения для объекта, но объект не обновляет значения для базы данных
Dynami c Метод
function getReaderRank (points) {let obj = {}; let rank = firebase.database (). ref ("ReaderRanks /"). Once ("значение", function (snaps) {snaps.forEach (function (child) {let item = child.val (); let i; для (i = 0; i <= item; i ++) {let strtVal = item.startValue; let endVal = item.endValue; </p>
if (points >= strtVal && points <= endVal) {
obj.userRankBadge = item.name;
obj.userRank = item.rank_no;
obj.userPoints = points.toFixed(2);
obj.commission = item.commission;
obj.userRankPrice = item.price;
}
}
});
}); вернуть obj;}