I
I
Igor Myasnikov2018-02-09 22:36:53
JavaScript
Igor Myasnikov, 2018-02-09 22:36:53

How to update data via fetch for only some fields?

Good day.
There is a fetch request:

class getData {
    fetch() {
        var data = fetch(url, myInit)
        .then(status)
        .then((data) => data.json())
        .catch((error) => {
            console.log('error', error)
    })
    return data;
    }
}

And by setTimeout there is an update
var timer = setTimeout(function tick() {
let getAPIData = new getData();

getAPIData.fetch().then(function get(data) {   
  ....
let a = Date.parse(alert.expiry);
let eta = expiry(a);
p2.innerHTML = `${eta}`;
 ....
}
timer = setTimeout(tick, 1000);
}, 100);
function expiry(ex) {
    let now = Date.now() /1000;
    let expiry = ex / 1000;
    
    let diff = expiry - now;
    let b = fortime(diff) // Просто формат даты

    return b
    
}

How to make sure that not all of the get function is updated, but only a few of its parts?
For example:
So that when updating a query, the data changes only in the eta variable

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Exploding, 2018-02-10
@pilium

Pass one more parameter to it (for example, an array of variable names that need to be updated or something else ...), based on which perform the necessary actions inside the function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question