Saturday 10 February 2018

Update a table populated with JSON data with a button click?

So I have a table of definitions that I want to be able to filter by category of the word. So when a user pressed a button it will sort by whichever category they pressed. How would I go about doing this, as I can only find examples that use forms, but mine isn't a form. I believe I will need to have a get request on the button that requests all the data with a certain category, however, I don't know how to do this.The JSON data{ "definitions":[ { "Category":"Algorithms", "Word":"Algorithm", "Meaning":"A process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer." },{ "Category":"Algorithms", "Word":"Binary Search", "Meaning":"Search a sorted array by repeatedly dividing the search interval in half. " },{ "Category":"Algorithms", "Word":"Linear Search", "Meaning":"Linear search, also known as sequential search, is a process that checks every element in the list sequentially until the desired element is found." },{ "Category":"Exchanging Data", "Word":"HTML", "Meaning":"Hypertext Markup Language, a standardized system for tagging text files to achieve font, colour, graphic, and hyperlink effects on World Wide Web pages." },{ "Category":"Exchanging Data", "Word":"TCP IP", "Meaning":"A set of network protocol layers that work together" },{ "Category":"Software Development", "Word":"Agile software development", "Meaning":"Agile software development is a group of software development methods in which requirements and solutions evolve through collaboration between self-organizing, cross-functional teams." } ] } How I am currently sending the dataapp.get('/definitions', function (req, res) { var contents = fs.readFileSync("defs.json"); var jsonContent = JSON.parse(contents); res.render('definitions', {title: "Title", defs: jsonContent.definitions}) }) And here's how I am populating the table using PUG (Formerly Jade).container.defs-body table.table.defs-table.table-hover thead.thead tr th Category th Word th Meaning tbody.defs-table-body each definition in defs tr td= definition.Category td= definition.Word td= definition.Meaning Thanks.

Submitted February 10, 2018 at 08:52PM by mexO2000

No comments:

Post a Comment