0
我有一個JS數組,應該只顯示一個元素。它的確如此,但它的索引是1而不是0,計數是2.此外,數組不顯示0索引。爲什麼我的JavaScript數組顯示兩個元素的數量應該只有一個?
我的代碼:
var _UnitOfMeasureRelatedUnitData = [];
var rows = $('#jqxUOMRelatedUnitsDropdownGrid').jqxGrid('getrows');
var RecordCount = 0;
if (rows.length !== 1 && rows[0]["UOMRelatedUnit_Name"] !== ""){
for(var i = 0; i < rows.length; i++){
var row = rows[i];
var _row = {};
if(row.UOMRelatedUnit_AddItem !== F) {
RecordCount += 1;
_row["Name"] = $("#txtUnitOfMeasureSetName").val();
_row["Active"] = T;
_row["UnitOfMeasureTypeID"] = $("input[type='radio'][id='rblUnitOfMeasureType']:checked").val();
_row["BaseUnitID"] = $("input[type='radio'][id='rblUnitOfMeasureBaseUnit']:checked").val();
_row["RelatedUnitDisplayOrder"] = RecordCount;
_row["RelatedUnitName"] = row.UOMRelatedUnit_Name;
_row["RelatedUnitAbbreviation"] = row.UOMRelatedUnit_Abbreviation;
_row["RelatedUnitConversionRatio"] = row.UOMRelatedUnit_ConversionOfBaseUnits;
_row["UnitOfMeasureSetID"] = UnitOfMeasureSetID;
_UnitOfMeasureRelatedUnitData[i] = _row;
}
}
....
}
在我JQX網格,我至少有四種選擇。對於這個問題,Ive只在Grid中選擇了2個選項,其值爲True,其他值均爲False。
我需要改變我的邏輯,因爲我現在看不到它?
編輯1
我忽略的RecordCount += 1;
的位置,我會嘗試將它移動到任務的結束,看看會發生什麼。
編輯2
放置並沒有區別。