1
我的表單上有2個網格。當您從第一個網格中選擇一條記錄時,它將用相關記錄填充第二個網格。此輔助網格具有「PEERGROUP」列,並且將包含「1」,「2」等值。如何從網格中構建唯一值列表?
我需要確保用戶至少選擇了屬於每個組的一條記錄。
我卡在試圖建立一個包含唯一組ID值的列表:
function CheckSelectionForGroups(gridName)
{
//Get rows in grid
var view = $('#' + gridName).data('kendoGrid').dataSource.view();
//Array to store the all distinct groups in the grid
var listOfGroups = [];
var listIndex = 0;
//Loop over the rows in the grid
for (var i = 0; i < view.length; i++)
{
//If the group is found in our list already, do nothing
if (listOfGroups[view[i].PEERGROUP])
continue;
//If the group was not found in our list, add it to the list.
listOfGroups[listIndex] = view[i].PEERGROUP;
listIndex = listIndex + 1;
}
//TODO - Loop over user selection
// and compare groups against list of groups
}
這裏是一些值的截圖:
(注:數組是不完整的,因爲如果我在處理下一行後截取屏幕截圖,它將錯誤地包含3個值:"1"
,"1"
和"2"
)
所以在這種情況下,我想要listOfGroups
只包含值"1"
和"2"
。我的for
循環內的if
聲明從不計算爲真。我嫌疑人 JavaScript正在將"1"
轉換爲1
,並試圖從listOfGroups
處索引1
處的元素。但我不知道如何解決這個問題?