すべての「li」要素をループしてデータを収集する機能があります。同様に、すべてのデータを配列にプッシュしています。すべての 'li' ループが終了したら、更新されたデータで関数を 1 回呼び出す必要がありますか?
私の現在のコードは次のようになっています: しかし、3 倍の条件を取得するため、3 倍の関数を呼び出します。関数は正常に動作します。関数を呼び出すのは間違っています。すべてのループを終了した後、一度呼び出すようにするための良い提案はありません。
var pieIndex = [];
$('button.pieDraw', $(accordionBox)).live('click', function () { //done button
var uls = $(accordionSec.accorGeography).find('ul');
$.each(uls, function (i, val) {
pieIndex = []; //i am clearing the array each time to get new value
var currentLI = $(val).find('li');
$(currentLI).each(function () {
if ($(this).hasClass('c_on')) { // this is finding the class 3 times. it's fine
var functionName = pieFunction[$(this).parent().attr('title') + 'Pie'].fun;
pieIndex.push($(this).attr('data-index')); // at the last i am getting 1,2,3 it's correct.
generatePieURL(functionName, curQI, crrentMonth, currentYear, pieIndex);
//it is calling 3 times. i need only one time to call..
}
})
})
});
前もって感謝します。