我有一个问题让这个工作。 我还是JS的新手并且学习语法。我试图修改某人的脚本,该脚本是为了在github-repository中返回 ALL 存储库(未经修改的工作正常)。 我试图修改它以仅返回具有指定主要语言的存储库,即' Matlab'。我现在可能已经被皇家屠杀了。
$(function () {
var lang = 'Matlab';
var lang2 = '#' + lang;
$('#' + lang).html('Loading...');
var username = 'lallers';
var requri = 'https://api.github.com/users/' + username;
var repouri = 'https://api.github.com/users/' + username + '/repos';
requestJSON(requri, function (json) {
var fullname = json.name;
var username = json.login;
var aviurl = json.avatar_url;
var profileurl = json.html_url;
var location = json.location;
var followersnum = json.followers;
var followingnum = json.following;
var reposnum = json.public_repos;
var email = json.email;
if (fullname == undefined) {
fullname = username;
}
var outhtml = '<div class="repolist clearfix"><ul>';
var repositories;
$.getJSON(repouri, function (json) {
repositories = json;
outputPageContent();
});
function outputPageContent() {
if (repositories.length == 0) {
outhtml = outhtml + '<p>No repos!</p></div>';
} else {
$.each(repositories, function (index) {
if (repositories[index].language == lang) {
outhtml = outhtml + '<li><a href="' + repositories[index].html_url + '" target="_blank">' + repositories[index].name + '</a></li>';
} else {
return true;
}
}); // end each statement
outhtml = outhtml + '</ul></div>';
} // end else statement
$('#' + lang).html(outhtml);
} // end else statement
}); // end requestJSON Ajax call
function requestJSON(url, callback) {
$.ajax({
url: url,
complete: function (xhr) {
callback.call(null, xhr.responseJSON);
}
});
}
});