1

showArray is a function witch show the content of json file, what's wrong in my function? why it doesn't work

function getArray() {
    var quest = [];
    $.getJSON('data.json', function (json) {
        for (var key in json) {
            if (json.hasOwnProperty(key)) {
                var item = json[key];
                quest.push({
                    Name:item.Name
                });
            }
        }
        callback(quest);
    });
}
$(document).ready(function () {
    getArray();
});
function showArray() {
    var callback = function (quest) {
        console.log(quest)
    }
}
4

1 に答える 1

1

callbackローカル変数です。getArray()おそらくパラメーターとして渡すことにより、関数に取得する必要があります。

于 2013-02-17T19:15:34.070 に答える