如何解决jQuery inArray / indexOf始终返回-1
So... I loaded json array trought Ajax,then I used $.each to put id values in an [] array.
Then I wanted to check if specific number that is in the variable exist in the array,so I tried using inArray and also indexOf in many different ways,tried changing to strings and integers,and nothing helped. I did waste few hours already at this...
Here's my Ajax code:
$.ajax({
method: "POST",url: "loadost.php",dataType: 'json',data: {
"id" : id
},success: function(ostloaded){
ostlength = ostloaded.length;
$.each($(ostloaded),function(key,value){
我添加了“ loaded_id”以确保它是整数,但没有帮助。
var loaded_id = parseInt(value.id);
idArray.push(loaded_id);
typ.push(value.typ);
link.push(value.link);
tyt_art.push(value.tytul_autor);
});
在这里我排序应该在何时何地创建元素
for(q = 0; q<=ostlength;q++){
if(typ[q] == 1){
$('<li class="op'+q+'"></li>').appendTo('body #ops');
$('<div/>').text(tyt_art[q]).appendTo('body .op'+q);
}
if(typ[q] == 2){
$('<li class="ed'+q+'"></li>').appendTo('body #eds');
$('<div/>').text(tyt_art[q]).appendTo('body .ed'+q);
}
if(typ[q] == 3){
$('<li class="ins'+q+'"></li>').appendTo('body #ins');
$('<div/>').text(tyt_art[q]).appendTo('body .ins'+q);
}
然后我创建播放列表
unflist.push(link[q]);
}
list = unflist.filter(function (el) {
return el != null;
});
loadsongs(0,list);
$(".playerHs").html(tyt_art[0]);
}
});
console.log($.inArray(pageId,idArray),idArray.indexOf(pageId),pageId,idArray);
输出无论如何-永远不会改变,总是这样:Console Log
我更改了变量的名称,以使它们更清晰。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。