I am using the tool sheety ( https://sheety.co/ ) to put information into Google Sheets.
Unfortunately, I'm not very savvy with json and have pieced this together as much as I could.
The problem is that when the function is triggered, other columns are also changed. Does anyone have a solution why this is so and how I can prevent this?
I would be happy if someone could help me. If you have any questions, please do not hesitate to contact me.
var products = null;
// Called once the page has loaded
document.addEventListener('DOMContentLoaded', function(event) {
loadItems();
});
var projectUrl = 'XXX';
function loadItems() {
fetch(projectUrl + '/products')
.then((response) => response.json())
.then(json => {
this.products = json.products.sort((a, b) => {
return a.erledigt < b.erledigt;
console.log(json.products);
})
showAllItems();
console.log(json.products);
});
}
function drawItems(products) {
var template = Handlebars.compile(document.getElementById("products-template").innerHTML);
document.getElementById('products-container').innerHTML = template({
products: products
});
}
function showAllItems() {
drawItems(this.products);
}
function upvoteItems(id) {
let product = this.products.find(product => {
return product.id == id;
});
product.done = 1;
let headers = new Headers();
headers.set('content-type', 'application/json');
fetch(projectUrl + '/products/' + id, {
method: 'PUT',
body: JSON.stringify({ product: product }),
headers: headers
});
showAllItems();
}