我正在编写node.js应用程序,我有点担心如何构建发送数据以发送到服务器.例如,当我想删除数据项时,我将所述项的id放在href属性中:
<a class='delete' href="1231">Delete this data</a>
<!-- href is based on a variable I'm pulling from the server -->
Run Code Online (Sandbox Code Playgroud)
单击该链接时,我会阻止默认操作,然后运行ajax请求:
//On click + ajax
body.on('click', '.delete', function(e){
e.preventDefault();
$.ajax({
type: 'POST',
url: '/admin/report/detail/delete',
data: {id: $(this).attr('href')},
success: function(){
//Success message
},
error: function(){
//Error message
}
});
});
Run Code Online (Sandbox Code Playgroud)
我想知道,以这种方式使用href属性是不好的做法吗?如果是这样,存储这些数据的最佳方法是什么?
我正在构建一个节点应用程序,在该应用程序中,用户可以(理想地)使用一系列JSON对象为地理数据定义样式:
{
"style":
{
"test": "year",
"condition": "<= 1954 AND >= 1936",
"color": "red"
}
}
Run Code Online (Sandbox Code Playgroud)
在上述情况下,我喜欢将该样式评估为
if (year <= 1954 && year >= 1936){
object.color = red;
}
Run Code Online (Sandbox Code Playgroud)
有没有简单的方法来解析+评估此类表达式/从此类对象构建它们?我对让人们将使用<=,> =,||,&&等构建的复杂表达式串在一起特别感兴趣。
如果可能的话,我想避免使用eval()。