我被困在这里,希望能得到一些指导。我正在尝试从提要中获取 XML,将一些元素放入数组中,然后传递给 jQuery 的 DatePicker 插件。我下面的代码显示日历,但不显示提要中的事件。Chrome 也不显示任何错误或警告。不知道发生了什么。非常感谢任何帮助。
(我的 XML):
<entry>
<published>2012-05-29T13:05:53-08:00</published>
<updated>2012-05-29T13:05:58-08:00</updated>
<title type="html">
<![CDATA[ Businesses Get Help With Legal Issues ]]>
</title>
<content type="html">
<![CDATA[ Click the article header for the complete story.
<!-- /Publications/26674.htm -->
]]>
</content>
<link rel="alternate" type="text/html" href="/Publications/26675.htm"/>
</entry>
(在外部 JS 文件中):
$(document).ready(function(){
var events = new Array();
events = getSelectedDates();
$("div.datepicker").datepicker({
beforeShowDay: function(date) {
var result = [true, '', null];
var matching = $.grep(events, function(event) {
return event.published.valueOf() === date.valueOf();
});
if (matching.length) {
result = [true, 'highlight', null];
}
return result;
},
onSelect: function(dateText) {
var date,
selectedDate = new Date(dateText),
i = 0,
event = null;
while (i < events.length && !event) {
date = events[i].published;
if (selectedDate.valueOf() === date.valueOf()) {
event = events[i];
}
i++;
}
if (event) {
alert(event.Title);
}
}
});
});
function getSelectedDates()
{
var the_selected_dates = new Array();
$.ajax(
{
url: 'news.xml',
type: 'GET',
dataType: 'xml',
async: false,
success: function(data)
{
$(data).find('entry').each(function(i, entryObj)
{
var entryObj = new Object();
entryObj.eTitle = $('title', this).text();
entryObj.eDate = $('published', this).text();
the_selected_dates.push(entryObj);
});
}
});
return the_selected_dates;
}