我有一個未執行的回調函數。我懷疑它被視爲一個字符串,但我不確定。 代碼如下。 此外,這裏有一個簡化的jsFiddle更詳細:http://jsfiddle.net/oakley808/sH5XE/3/Javascript回調函數未執行
基本上它只是迭代for循環,使用對象的設置。最後一行config.feeds[i].cb
是失敗的。想法任何人?
// the callback function
function rssdone(){
$('#cbBlock').append('did some callback stuff<br>');
}
// the settings for the loop below
var config = {
"feeds": [
{
"container": "#block1",
"url":"http://apps1.eere.energy.gov/news/rss/program.cfm?topic=1010",
"limit":"4",
"layoutTemplate": "<ol type='1'>{entries}</ol>",
"entryTemplate": "<li>{title}</li>",
"cb":"rssdone"
},
{
"container": "#block2",
"url":"http://apps1.eere.energy.gov/news/rss/financial_opps_solar.cfm",
"limit":"2",
"layoutTemplate": "<ol type='A'>{entries}</ol>",
"entryTemplate": "<li>{title}</li>",
"cb":"rssdone"
}
]
}
// the logic
for(var i=0; i < config.feeds.length; i+=1) {
$(config.feeds[i].container).rss(
config.feeds[i].url,
{
limit: config.feeds[i].limit,
layoutTemplate: config.feeds[i].layoutTemplate,
entryTemplate: config.feeds[i].entryTemplate
},
// this fails to use the callback for some reason
config.feeds[i].cb
// use this instead and it works!
// rssdone
);
}