0
尝试解析某些直播流JSON数据并查看事件是否具有特定标记。 如果它不那么我会用这些数据来输出值等从Javascript函数返回JSON对象
无论出于何种原因,upcoming_event
没有被指派的事件对象(这是findPublicEvent
函数的返回值。
事件对象的执行console.log工作正常 - 但它返回不工作:/
// get our NLC data from livestream.
// -> note: need the '?callback=?' to convert to JSONP for cross-domain usage
var $uri = 'http://api.new.livestream.com/accounts/newlifechurchtv/?callback=?';
$.getJSON($uri, function(data) {
parseNLCData(data);
});
parseNLCData = function(nlc_data){
// set our variable to the return first event
// nlc_data.upcoming_events.data is a json array of events
window.upcoming_event = findPublicEvent(nlc_data.upcoming_events.data);
}
// should return single public event
function findPublicEvent (all_events) {
// if we have events
if (all_events) {
// loop through events to find public event
$.each(all_events, function(index,value){
// get all the tags, remove whitespace, and put into array
var $tags = value.tags.replace(/ /g, '').toLowerCase().split(',');
// check for privacy.
var $privacy = $.inArray('private', $tags);
if ($privacy === -1) {
// if the event isn't private -> return it!
console.log(value);
return value;
}
});
// otherwise .... ->
} else {
// we don't have events, sooo, no dice.
return false;
}
};
非常感谢您的帮助@Quentin!像魅力一样工作:D – watts 2013-03-14 17:59:11