Mootools正在为JSON结果添加不需要的函数调用

时间:2012-11-27 22:00:43

标签: javascript jquery asp.net ajax mootools

我有一个函数可以获取asp.net页面中的车辆列表

 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中完成的。

1 个答案:

答案 0 :(得分: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