我试图使用以下转换使用json2html呈现锚点:
'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中,我以o/p的形式得到以下内容:
<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请帮我解决这个问题。
发布于 2014-12-17 09:27:46
以下代码解决了我的问题:
'renderTimeline':[ {
tag: "a",
class: "btn btn-warning btn-circle",
style: "float: right;",
html: "<i class=\"icon-remove\"></i>",
"onclick": function(e) {
delSchedule(e);
}}
}]如果我要通过下面的json:
{ monday:[ { startTime:10:00, endTime: 12:00, room_id:cse124 }, { startTime:13:00, endTime: 15:00, room_id:lotus } ] }我希望能够访问函数delSchedule()中的“星期一”。我该怎么做?请帮帮忙。
发布于 2014-12-16 10:23:10
假设您试图将单击元素的引用传递给delSchedule函数,则需要更改href定义如下:
"href": function() {
var myhref = "javascript:delSchedule(this);"; // note 'this' is part of the string, not concatenated
return myhref;
}发布于 2014-12-16 10:25:16
{
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;
}
}https://stackoverflow.com/questions/27502244
复制相似问题