使用条件有两个值

时间:2021-08-29 13:13:26

I wanna use show / hide div function with localStorage. So I wrote this code scope:

我想用localStorage使用show / hide div函数。所以我写了这个代码范围:

 function getLocalDatas (clickedBefore, data, nid, vote, advpoll_choice, title, element) {
        for(var nid in actualPolls){

          var nids = [];
          var nids = JSON.stringify(actualPolls[nid].nid);
          // console.log('id '+ ids);
          console.log('here '+ nids);
        }
        for(var i in localStorage){

          var ids = JSON.stringify(localStorage[i]);
          // console.log('id '+ ids);
          console.log('nid '+ ids);
        }
        if(ids == nids) {
          console.log('ids '+ids);
          vm.clickedBefore = true;
          console.log(vm.clickedBefore);
          console.log("done");

        } else {
          console.log('ids '+ids);
          console.log('nids '+nids);
          console.log("not done");
        }

     // return i;
   }
   getLocalDatas();

I checked for values on console.log I dont know why but it shows last items each values. I need sort for values and use them in condition. Whats the wrong? How can I solve it. Thanks.

我检查了console.log上的值我不知道为什么,但它显示每个值的最后项目。我需要对值进行排序并在条件中使用它们。怎么回事?我该怎么解决呢谢谢。

2 个解决方案

#1


0  

Answering your question based on additional input provided in comments: in order to compare array elements use the index, like nids[1], nids[2] or nids[i] if within the for loop. The same applies to the second array ids. Hope this will help.

根据注释中提供的其他输入回答您的问题:为了比较数组元素,使用索引,如nids [1],nids [2]或nids [i],如果在for循环中。这同样适用于第二个数组ID。希望这会有所帮助。

#2


0  

    function getLocalDatas (clickedBefore, data, nid, vote, advpoll_choice, title, element) {
    for(var nid in actualPolls){

      var nids = [];
      var nids[]= JSON.stringify(actualPolls[nid].nid);
      // console.log('id '+ ids);
      console.log('here '+ nids);
    }
    for(var i in localStorage){
      var ids = [];
      var ids[] = JSON.stringify(localStorage[i]);
      // console.log('id '+ ids);
      console.log('nid '+ ids);
    }
    for(var i = 0; i< ids.length; i++){
    if(ids[i] == nids[i]) {
      console.log('ids '+ids);
      vm.clickedBefore = true; 
      console.log(vm.clickedBefore);
      console.log("done");

    } else {
      console.log('ids '+ids);
      console.log('nids '+nids);
      console.log("not done");
    }
    }

 // return i;
    }
    getLocalDatas();

I think this is what you want code is not ordered . It's hard to order from mobile

我认为这是你想要的代码没有订购。从移动设备订购很难

#1


0  

Answering your question based on additional input provided in comments: in order to compare array elements use the index, like nids[1], nids[2] or nids[i] if within the for loop. The same applies to the second array ids. Hope this will help.

根据注释中提供的其他输入回答您的问题:为了比较数组元素,使用索引,如nids [1],nids [2]或nids [i],如果在for循环中。这同样适用于第二个数组ID。希望这会有所帮助。

#2


0  

    function getLocalDatas (clickedBefore, data, nid, vote, advpoll_choice, title, element) {
    for(var nid in actualPolls){

      var nids = [];
      var nids[]= JSON.stringify(actualPolls[nid].nid);
      // console.log('id '+ ids);
      console.log('here '+ nids);
    }
    for(var i in localStorage){
      var ids = [];
      var ids[] = JSON.stringify(localStorage[i]);
      // console.log('id '+ ids);
      console.log('nid '+ ids);
    }
    for(var i = 0; i< ids.length; i++){
    if(ids[i] == nids[i]) {
      console.log('ids '+ids);
      vm.clickedBefore = true; 
      console.log(vm.clickedBefore);
      console.log("done");

    } else {
      console.log('ids '+ids);
      console.log('nids '+nids);
      console.log("not done");
    }
    }

 // return i;
    }
    getLocalDatas();

I think this is what you want code is not ordered . It's hard to order from mobile

我认为这是你想要的代码没有订购。从移动设备订购很难