New to ionic and 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];
}
};
},
};
})
It is normal for the "//mark" to be like this, but change it to return recos[0] or recos[1]... The data will not be displayed when called in the front desk. Why is this~; Because I want to make a simple Matching function:
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];
}
};
},
};
I encountered this problem and I don’t know the reason.
滿天的星座2017-05-15 17:00:30
allreco should mean returning all recos. Why does it become return recos[i]? Do you want to return all recos in localStorage.city?
allreco: function(){
var city = localStorage.city;
var result=[]
for (var i = 0; i < recos.length; i++) {
if (city.indexOf(recos[i].cityname) != -1){
result.push(recos[i]);
}
};
return result;
}