javascript中复选框列表的优先级

javascript中复选框列表的优先级,javascript,arrays,sorting,logic,Javascript,Arrays,Sorting,Logic,我试图将记录按优先级顺序存储在3个不同的列表中\ 我的要求如下: 假设表中有10条记录行,每条记录上有3个复选框(复选框1、复选框2、复选框3) Checkbox1的优先级最高,Checkbox3的优先级最低 用例:如果我为一条记录选择了所有3个复选框,则只考虑复选框1 用例:如果我选择Checkbox2和Checkbox3,则只考虑Checkbox2 用例:如果我选择Checkbox1和Checkbox3,则只考虑Checkbox1,因此适用于所有其他类似条件 我已经尝试过,并且在所有条件下都

我试图将记录按优先级顺序存储在3个不同的列表中\

我的要求如下:

  • 假设表中有10条记录行,每条记录上有3个复选框(复选框1、复选框2、复选框3)
  • Checkbox1的优先级最高,Checkbox3的优先级最低
  • 用例:如果我为一条记录选择了所有3个复选框,则只考虑复选框1
  • 用例:如果我选择Checkbox2和Checkbox3,则只考虑Checkbox2
  • 用例:如果我选择Checkbox1和Checkbox3,则只考虑Checkbox1,因此适用于所有其他类似条件
  • 我已经尝试过,并且在所有条件下都能完美地工作,除了取消对更高戒律的选择。此处allRecordList将在屏幕上显示所有ID

       for (var i = 0; i < this.allRecordList.length; i++) {
    
            if (this.selectedCheckbox1Ids.indexOf(this.allRecordList[i].Id) != -1) {                                
                this.Checkbox1SelectedRecords.push(this.allRecordList[i]);  
                //removing from c2 list
                if (this.selectedCheckbox2Ids.indexOf(this.allRecordList[i].Id)  != -1){
                    this.selectedCheckbox2Ids.splice(this.selectedCheckbox2Ids.indexOf(this.allRecordList[i].Id),1);
    
                }
                //removing from c3 list
                if (this.selectedCheckbox3Ids.indexOf(this.allRecordList[i].Id)  != -1){
                    this.selectedCheckbox3Ids.splice(this.selectedCheckbox3Ids.indexOf(this.allRecordList[i].Id),1);
    
                }
    
    
            if (this.selectedCheckbox2Ids.indexOf(this.allRecordList[i].Id) != -1 ) {
                this.referralSelectedRecords.push(this.allRecordList[i]);   
                //removing from c3 list
                if (this.selectedCheckbox3Ids.indexOf(this.allRecordList[i].Id)  != -1){
                    this.selectedCheckbox3Ids.splice(this.selectedCheckbox3Ids.indexOf(this.allRecordList[i].Id),1);
    
                //removing from c1 list 
                if (this.selectedCheckbox1Ids.indexOf(this.allRecordList[i].Id)  != -1){
                    this.selectedCheckbox1Ids.splice(this.selectedCheckbox1Ids.indexOf(this.allRecordList[i].Id),1);
                }                   
    
            }
            // c3 handle
            if (this.selectedCheckbox3Ids.indexOf(this.allRecordList[i].Id) != -1 ) {
                this.informationSelectedRecords.push(this.allRecordList[i]);
                console.log('Select Selected Info '+this.selectedCheckbox3Ids);
                ////removing from c2 list
                if (this.selectedCheckbox2Ids.indexOf(this.allRecordList[i].Id)  != -1){
                    this.selectedCheckbox2Ids.splice(this.selectedCheckbox2Ids.indexOf(this.allRecordList[i].Id),1);
                }
                //removing from c1 list
                if (this.selectedCheckbox1Ids.indexOf(this.allRecordList[i].Id)  != -1){
                    this.selectedCheckbox1Ids.splice(this.selectedCheckbox1Ids.indexOf(this.allRecordList[i].Id),1);
                }                   
            }
    
        }
    
    for(var i=0;i
  • 有什么有效的方法来处理这个问题吗?我无法重新计算优先级逻辑。
    如果有任何帮助,我们将不胜感激。

    javascript已经有了允许存储键、值对的映射。也许您可以使用映射来映射每一行及其优先级,例如将键作为行id,将值作为优先级,并根据所选优先级更新键的值。您可以找到

    
    函数更新映射(rowid、boxid、box){
    如果(复选框){
    if(testMap.get(rowid)==undefined | | | testMap.get(rowid)==-1 | | | testMap.get(rowid)>boxid){
    testMap.set(rowid,boxid)
    }
    }否则{
    对于(i=1;i{
    document.getElementById(“结果”).innerHTML=document.getElementById(“结果”).innerHTML+“行:”+key+“优先级:”+value+“
    ”; }); }
    请单击编辑,然后单击
    []
    代码段编辑器并创建一个
    
    function updateMap(rowid, boxid, box) {
    if (box.checked) {
     if (testMap.get(rowid) === undefined || testMap.get(rowid) === -1 || testMap.get(rowid) > boxid) {
       testMap.set(rowid, boxid)
     }
    } else {
     for (i = 1; i <= 4; i++) {
       if (i === 4) {
         testMap.set(rowid, -1)
         break;
       }
    
       if (document.getElementById("row" + rowid + "box" + i).checked) {
         testMap.set(rowid, i);
         break;
       }
    
     }
    }
    
    }
    
    function logresulty() {
    document.getElementById("result").innerHTML = ""
    testMap.forEach((value, key) => {
     document.getElementById("result").innerHTML = document.getElementById("result").innerHTML + " row:" + key + " Priority:" + value + "<br>";
    });
    }