我想循环ajax响应
$scope.annotateColorbox03 = {
rel: 'img-group-01',
slideshow: false,
open: false,
onComplete: function () {
console.log('03-complete');
var photo = colorboxService.getCurrentPhoto();
if (photo.src) {
console.log('annotateColorbox03 ' + photo.src);
annotoriousService.makeAnnotatable(photo);
var annotations = annotoriousService.getAnnotations(photo.src);
console.log(annotations);
if (annotations && annotations.length > 0) {
annotoriousService.showAnnotations(photo.src);
colorboxService.resize();
}
}
},
onLoad: function () {
console.log('03-onLoad');
annotatableImage();
},
onCleanup: function () {
console.log('03-cleanup');
annotatableImage();
}
};
function annotatableImage() {
var photo = colorboxService.getCurrentPhoto();
if (photo && photo.src) {
//required
annotoriousService.reset(photo.src);
}
}
我想要response = [
["u.profile"],
["r.useractivity"],
["i.items_job"],
["i.setup"],
["search"],
["i.items_assortment"]
]
data = u.profile;
等
尝试方法:
data = r.useractivity;
在控制台中获取错误
Uncaught TypeError:无法使用'in'运算符在[[“u.profile”],[“r.useractivity”],[“i.items_job”],[“i.setup”中搜索'length' ],[ “搜索”],[ “i.items_assortment”]]
答案 0 :(得分:0)
问题是你的response
var是一个数组(一个对象)数组,默认键是整数。
如果你可以将它改成像这样的字符串数组,那将是一种更简单(更好)的方法:
var response = ["u.profile",
"r.useractivity",
"i.items_job",
"i.setup",
"search",
"i.items_assortment"];
有了这个,您可以像这样轻松循环response
:
for(var info in response)
console.log(info+':'+response[info]);
希望这会有所帮助!