J
J
Jake Taylor2022-01-26 13:53:16
Handlebars
Jake Taylor, 2022-01-26 13:53:16

How to update the value of the handlebars expression?

Index.hbs has an expression {{#each gifts}} , which iterates over the gifts object .

const fileContent = fs.readFileSync('./src/webapp/json/gifts.json', 'utf8');
const content = JSON.parse(fileContent);

exports.methodGet = function (request, response) {
    response.render('index.hbs', {
        gifts: content
    });
}


How can the value of gifts be updated after the initial hbs page loads?

Sequence of events:
1. The user visits http://host:port/
2. Using JS, we process the onkeyup event on the input
field on the client side 3. Using XMLHttpRequest , I send a POST request to the same address http://host:port/
4. On the Node.JS server side, I get the value entered in input in step 3
5. How do I update the gifts value in index.hbs now ?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question