我的功能是:
function collect_que_ids(e) {
var val = e.val();
var data_lo = e.attr('data-lo');
new_hash = {};
new_hash[val] = data_lo;
if(e.is(':checked')){
if(checked_Box_hash.includes(new_hash)){
checked_Box_hash;
}else{
checked_Box_hash.push(new_hash);
}
}
else{
new_hash_key = Object.keys(new_hash)[0]
new_hash_value = new_hash[new_hash_key]
$.each(checked_Box_hash,function(key,value){
if (typeof Object.keys(value) !== 'nil') {
current_key = Object.keys(value)
if (current_key[0] == new_hash_key && value[current_key[0]] == new_hash_value) {
checked_Box_hash.splice(key,1)
}
}
})
}
};
我在这条线上遇到错误.
if (typeof Object.keys(value) !== 'nil') {
需要解决它.请帮忙.
最佳答案
Object.keys(value)返回一个数组并检查它是否未定义或为空执行此操作
if (typeof Object.keys(value) !== 'undefined' && Object.keys(value).length > 0) {
// You have an array
}