剛接觸ionic和angular:
.factory('Recos', function() {
var recos=
[
{
recoid:0,
cityname:"上海",
cityintroduce:"",
citytext:"",
img:"",
},
{
recoid:1,
cityname:"北京",
cityintroduce:"",
citytext:"",
img:"",
},
{
recoid:2,
cityname:"深圳",
cityintroduce:"",
citytext:"",
img:"",
},
{
recoid:3,
cityname:"",
cityintroduce:"",
citytext:"”。",
img:"",
}
];
return {
allreco: function() {
return recos; //标注
},
get: function(recoid) {
for (var i = 0; i < recos.length; i++) {
if (recos[i].recoid === parseInt(recoid)) {
return recos[i];
}
};
},
};
})
"//標註"的地方這樣是正常的,但是改成return recos[0]或者recos[1]...前台調用就不顯示數據,這是為什麼呢~;因為想做一個簡單的匹配功能:
return {
allreco: function() {
var city = localStorage.city;
for (var i = 0; i < recos.length; i++) {
if (city.indexOf(recos[i].cityname) != -1){
return recos[i];
}
};
},
get: function(recoid) {
for (var i = 0; i < recos.length; i++) {
if (recos[i].recoid === parseInt(recoid)) {
return recos[i];
}
};
},
};
碰到了這個問題,不知道其中原因。
allreco的意思應該是返回所有的reco,為什麼會變成return recos[i],你是想返回所有在localStorage.city裡面的reco嗎?