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