github에서 JSON 객체를 가져 오는 다음 코드를 가지고 특정 배열을 배열에 추가하려고합니다.콜백 함수가 실행되지 않는 것처럼 보입니다
function getTree(hash) {
var pathToTree, returnedJSON;
pathToTree = 'https://api.github.com/repos/myaccount/myrepo/git/trees/' + hash;
$.ajax({
accepts: 'application/vnd.github-blob.raw',
dataType: 'jsonp',
url: pathToTree,
success: function (json) {
returnedJSON = json;
},
error: function (error) {
console.debug(error);
}
});
return returnedJSON;
}
function parseTree(hash) {
var objectedJSON, objectList = [], i, entry;
objectedJSON = getTree(hash, function() {
console.debug(objectedJSON); // this is not appearing in console
for (i = 0; i < objectedJSON.data.tree.length; i += 1) {
entry = objectedJSON.data.tree[i];
console.debug(entry);
if (entry.type === 'blob') {
if (entry.type.slice(-4) === '.svg') { // we only want the svg images not the ignore file and README etc
objectList.append(i.content);
}
} else if (entry.type === 'tree') {
objectList.append(parseTree(getTree(entry.sha)));
}
}
});
return objectList;
}
$(document).ready(function() {
var objects = parseTree('master', function() {
console.debug(objects);
});
});
가 나는 코드 JSON 객체의 벌금을 검색을 가지고 있지만 (일명 내가 원하는 비트를 잡아 당겨) 구문 분석려고 할 때 나는 문제로 실행합니다. 내가 사용하고있는 콜백은 진행중인 것 같지 않고 누군가가 그것을보고 도와 줄 수 있는지 궁금해하고있었습니다.
특히 내가 선택한 모든 기능에 콜백을 추가 할 수 있습니까? 나는 그 기능에 대해 무엇인가해야만 하는가?