刚接触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 should mean returning all recos. Why does it become return recos[i]? Do you want to return all recos in localStorage.city?