約 10 個の関数を反復処理する JavaScript の関数を作成しようとしています。
関数にjson URLを呼び出すサービスを作成する関数があります。これは以下のメイン関数と通信し、対応する URL へのオプションを指定してサービス関数を呼び出し、json 要求を開始するためのデータとして使用します。下記を参照してください;
var landp = {
getCountryCode : function(){
    console.info('landp.GetCountryCode');
    return window.location.pathname.match(/\/([a-zA-Z]{2})/)[1].toLowerCase();
},
Service : {
    getBaseUrl : function(){
        console.info('landp.Service.GetBaseUrl');
        return sprintf("/%s/service", landp.getCountryCode())
    },
    callService : function(method, options){
        console.info('landp.Service.CallService');
        var url = sprintf("%s/%s", landp.Service.getBaseUrl(), method);
        $.ajax({
            url : url,
            method : 'GET',
            success : options.success,
            error : options.error
        })
    },
    getCategories : function(options){
        landp.Service.callService('category', options);
    },
    getCategoryId : function(options){
        landp.Service.callService('category/id/13', options);
    },
            getCategoryTopTen : function(options){
        landp.Service.callService('category/name/top-ten', options);
    },
    getSeeMoreItems : function(options){
        landp.Service.callService('see-more', options);
    },
    getPartnerOffers : function(options){
        landp.Service.callService('partner-offers', options);
    }
}
}
getCategoryTopTen が、item.name、item.description などの適切なアイテムを取得するために使用する必要がある json データを保持する URL を呼び出すことがわかるので、これは正常に機能します。このコードは以下のとおりです。
landp.Service.getCategoryTopTen({
    success : function(data){
        $('#header').after('<div id="cat-sub-options"></div>');
        $('#cat-sub-options').after('<div class="flexslider"><ul class="slides"></ul></div><div id="carousel-button" class="click"></div>');            
        $.each(data[0].items, function(i, item){
        $('.flexslider .slides').append('<li class=""><h5>' + i + '</h5><a href="' + item.url + '"><img src="' + item.imageLargeUrl + '" alt="' + item.name + ' image" /><span>' + item.name + '</span></a></li>');
    });
    },
    error : function(){
        console.log("Error getting categories");
    }
})
ご覧のとおり、コードは上記で機能し、正しい情報を正しい要素などに取り込みます。現在、次のような約 10 のカテゴリがあります。
getCategoryTopTen getCategoryHistoryHeritage getCategoryWheretogo getCategoryショッピング getCategorySportyPeople
ご覧のとおり、それぞれが json ファイルのカテゴリ URL に割り当てられます。
私が修正しようとしているのは、たとえば次のすべてのカテゴリに対して上記を行う方法です: landp.Service.getCategoryTopTen すべてのカテゴリに itout を記述する代わりに、以下のコードを使用して、代わりに各関数に変数を渡すことはできますか?すべてのカテゴリでこれらの json 呼び出しをそれぞれ実行する必要があります。
どんな助けでも大歓迎です。
ありがとう、マーク