我正在尝试通过以下转换使用 json2html 渲染 anchor :
'renderTimeline':[ {
tag: "a",
class: "btn btn-warning btn-circle",
style: "float: right;",
html: "<i class=\"icon-remove\"></i>",
"href": function() {
var myhref = "javascript:delSchedule(" + this + ");";
return myhref;
}
}]
目的是删除 json 对象,该对象通过以下方式传递给它:
$('#sunTimeLine').json2html(sched1.sunday, transforms.renderTimeline, {'events':true});
我在渲染的 html 上得到以下结果:
<a class="btn btn-warning btn-circle" style="float: right;" href="javascript:delSchedule([object Object]);"><i class="icon-remove"></i></a>
当我点击链接(按钮)时,我在浏览器控制台中收到一条消息:
SyntaxError: missing ] after element list
请帮我解决这个问题。
最佳答案
假设您尝试将单击的元素的引用传递给 delSchedule
函数,则需要更改 href
定义,如下所示:
"href": function() {
var myhref = "javascript:delSchedule(this);"; // note 'this' is part of the string, not concatenated
return myhref;
}
关于javascript - 使用 json2html 渲染 anchor href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27502244/