使用单击按钮更新填充了JSON数据的表格?

时间:2018-02-10 19:27:40

标签: json node.js pug

所以我有一个定义表,我希望能够按该词的类别进行过滤。因此,当用户按下按钮时,它将按他们按下的任何类别进行排序。我将如何做到这一点,因为我只能找到使用表格的例子,但我的表格并不是。我相信我需要在按钮上获取请求所有具有特定类别的数据的请求,但是,我不知道如何执行此操作。

JSON数据

{
  "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."
    }
  ]
}

我目前如何发送数据

app.get('/definitions', function (req, res) {
  var contents = fs.readFileSync("defs.json");
  var jsonContent = JSON.parse(contents);
  res.render('definitions', {title: "Title", defs: jsonContent.definitions})
})

以下是我如何使用PUG(以前的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

感谢。

0 个答案:

没有答案