【发布时间】:2018-07-23 19:19:31
【问题描述】:
我正在使用x-editable 编辑内容。在官方文档中它说“打开您的页面并单击元素。输入新值并提交表单。它将向/post发送带有新值的ajax请求”。
这是我想做的,但是我的网址是动态的。我想知道如何生成动态网址?
这是显示内容和可编辑启用的 UI:
现在我只要在浏览器中输入http://localhost:5055/update/department?id=55&name=yoo,我的UI上的相应内容就会更新。问题是每个数据都有不同的id和不同的名称,所以url会是动态的/update/department?id=dynamicID&name=newvalue
如何使用 x-editable 生成动态 URL?
目前我在我的<a> 中添加data-url="/update/department?id=${department.optString("departmentId")}&name=",但无法弄清楚如何设置name=。
在我的 js 文件中,我尝试了:
$('.to-be-edited').editable({
toggle: 'manual',
//submit data without pk please set send option to "always".
//send: 'always',
url: '$(this).data("url") + newValue',
success: function(res, newValue) {
console.log(newValue)
}
})
我得到一个错误:
POST http://localhost:8000/update/department?id=55&name= 405 (Method Not Allowed)
渲染表格的代码
<c:if test="${departments.length() > 0}">
<c:forEach var="i" begin="0" end="${departments.length()-1}">
<c:set var="department" value="${departments.getJSONObject(i)}"/>
<tr>
<td><a href="#"
class="to-be-edited department-name" data-type="text"
data-pk="${department.optString("departmentId")}"
id="${department.optString("departmentId")}"
data-url="/update/department?id=${department.optString("departmentId")}&name=">${department.optString("departmentName")}</a><i class="fa fa-pencil-square-o fa-fw pencil-edit-name" aria-hidden="true"></i></td>
<td> <a href="#" class="edit-name">Edit Name</a> </td>
</tr>
</c:forEach>
</c:if>
【问题讨论】:
标签: jquery x-editable