2012-11-27 29 views
0

我在一個asp.net頁面獲取車輛列表MooTools是增加不必要的函數調用JSON結果

function GetVehicleCounts(totalVehicles, vehiclesInDepot, vehiclesInFilter,   vehiclesInKnownLocations, vehiclesInUnknownLocations, vehiclesNotInDepot) 
{ 
vehiclesInDepot.value = 0; 
vehiclesInFilter.value = 0; 
vehiclesInKnownLocations.value = 0; 
vehiclesInUnknownLocations.value = 0; 
vehiclesNotInDepot.value = 0; 
var listofVehicles; 
var count = 0; 

for (var k in vehicles_dm) { 
    vehiclesInDepot.value++; 

    if (vehicles_dm[k].IsInFilter) { 
     vehiclesInFilter.value++; 
    } 

    if (vehicles_dm[k].CurrentFeatureType == 11) { 
     vehiclesInUnknownLocations.value++;    
    } 
    else { 
     vehiclesInKnownLocations.value++; 
    } 
} 

if (vehicles_dm != null) { 
    vehiclesNotInDepot.value = totalVehicles - vehicles_dm.length; 
} 
} 

然而功能,當我添加MooTools的頁面我遇到的問題Mootools將所有函數調用添加到結果中。這最終會重複執行任何類似的功能。任何想法糾正?

我沒有關於使用Mootools的選擇,現有的頁面是在jQuery中完成的。

+0

「將所有的函數調用的結果」 - 這是沒有意義的,請詳細說明是,正在添加 –

+0

專門_which_函數調用? – BryanH

+0

爲什麼在第一個函數def的末尾有一個撇號?它使第二個函數成爲一個字符串。這是一個錯字,只是在SO或在您的js文件? –

回答

0

我找到了答案!

'for..in不適用於數組迭代。它遍歷一個非內置對象的所有屬性。由於MooTools爲Array原型添加了更多功能,因此它們現在也是數組屬性。看到這個https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Statements/For...in

只是使用基本for循環進行數組迭代。'

Javascript array iteration using for..in with MooTools included

+1

相當,就像我在評論中所說的 - 你正在做'var in'。 –

相關問題