问题描述
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 (将#修改为@)