我正在尝试将具有不同数据类型的对象传递给角度中的$ location服务。什么有效,什么无效:
当我传递正常数组时:
[
key: "page",
value: 1
],
[
key: "color",
value: "red"
]
我使用这段代码:
angular.forEach(myArray, function (data, index) {
$location.search(data.key, data.value.toString());
});
我得到了预期的网址:abc.com?page=1&color=1
当我沿着先前的数据传递数组时:
[
key: "page",
value: 1
],
[
key: "color",
value: "red"
],
[
key: "names[]",
value: ["jack", "steve", "mark", "larry"]
]
我使用这段代码:
angular.forEach(myArray, function (data, index) {
if( typeof data.value === "object" ){
var obj = {};
obj[data.key] = data.value;
$location.search(obj);
}
else{
$location.search(data.key, data.value.toString());
}
});
我明白了:abc.com?name[]=jack&name[]=steve&name[]=mark&name[]=larry
但我期待:abc.com?name[]=jack&name[]=steve&name[]=mark&name[]=larry&?page=1&color=1
page
和color
参数在哪里?