我有多个div返回这样的数组:
[{"k":"Model","v":"box"},{"k":"Color","v":"blue"},{"k":"Size","v":"med"},{"k":"Type","v":"good"}]
Run Code Online (Sandbox Code Playgroud)
有时,非数组项又回来了,我想忽略那些。
可以是空格或随机无序的空白列表。因此,我只想只处理返回的数组,其余的留空。
我如何检查它是否为数组,而忽略其余部分?
jQuery('.overview').each(function () {
var $overview = jQuery(this),
specs = jQuery.parseJSON($overview.html());
if ( !! specs) {
$overview.html('<div class="bullet_spec"></div>');
jQuery.each(specs, function () {
$overview.children('div').append('<ul class="specs"><li class="label">' + this.k + ' : ' + this.v + '</li></ul>');
});
} else { // leave blank?? not sure what to do here
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的小提琴:http : //jsfiddle.net/veGPN/
谢谢