0

Im kind a new to jaggery(http://jaggeryjs.org/) and I'm implementing a sample site using this technology. I have the following file in my file directory

employees.json (note: ignore the validation of the data)

{
    "employees": [
        {
            "id": "1",
            "name": "2",
            "age": "3",
            "town": "4",
            "salary": "5"
        },
        {
            "id": "3",
            "name": "fd jf",
            "age": "dfkd jf",
            "town": " jdks fj",
            "salary": " fjkdf "
        },
        {
            "id": "1",
            "name": "2",
            "age": "3",
            "town": "4",
            "salary": "5"
        }
    ]
}

I displayed this data using html table below and i included function to delete the json element within that row itself.

index.jag(note: this is a part of that code)

    <head>
<link rel="stylesheet" type="text/css" href="style.css" />
<%
var json = require("employees.json");
%>
</head>
<body>
 <h1>Employee Details</h1>
 <%
 include ("new_employee.jag");
 %>
 <h2>List all Employees</h2>
 <table "employeesTable" border="2">
  <tr>
   <th>Emplyee ID</th>
   <th>Name</th>
   <th>Age</th>
   <th>Town</th>
   <th>Salary</th>
  </tr>
  <%
  for (var i in json.employees){
%>
  <tr>
   <td><%=json.employees[i].id%></td>
   <td><%=json.employees[i].name%></td>
   <td><%=json.employees[i].age%></td>
   <td><%=json.employees[i].town%></td>
   <td><%=json.employees[i].salary%></td>
       <td><%delete employees[i]%></td>
      </tr>
      <%
     }

     %>

     </table>

as you can see my delete function is wrong because i could find any resource document that guid me to delete json element i.

Can some help me to delete this json element using Jaggery.

4

4 回答 4

1

如果你想做harsha89提到的事情,你可以在服务器上对jag脚本进行ajax调用,并使用回调函数异步删除和更新表(假设表是从服务器端源填充的)如果你需要只需删除客户端 JQuery 上的表元素就很容易了。

于 2014-08-19T11:29:00.260 回答
1

如果要删除第一个元素,请尝试。

例子 -:

<%delete json.employees[o]%> //delete the first element element

然后打印数组看看。

于 2014-08-20T07:41:31.737 回答
1

尝试

<%delete json.employees[i]%>

这会成功的

于 2014-08-19T12:03:12.673 回答
0

据我了解,您想要一个链接,以便您需要删除整行,对吗?这不是这样做的方法。您需要做的是,使用 jQuery 与该链接的侦听器建立链接。单击删除链接时,您必须使用 JQuery 从表中删除该行。我认为使用员工 ID 作为行 ID 是使用 JQuery 删除该行的理想选择。请参阅 [1] 和 [2]。

[1]-使用 jQuery 删除表格行

[2]-删除具有特定 id 的表行

于 2014-08-19T09:42:50.183 回答