你需要让你的服务返回的结果,因为在你的承诺,它将返回整个响应,但你只需要提供的结果,所以只是在你的服务中添加映射。
this.getOptions = function(prefix) {
return $http.get('http://search.ams.usda.gov/farmersmarkets/v1/data.svc/zipSearch?zip=60629').then(function(response){
return response.data.results; //Return results
});
};
,并在您的视图做一些改变来适应数据: -
typeahead="option as option.marketName for option in getOptions($viewValue)"
<h4><span bind-html-unsafe="match.model.marketname | typeaheadHighlight:query"></span></h4>
Demo
或者在您的服务来回报预期的数据格式使用映射器在返回数据: -
return $http.get('http://search.ams.usda.gov/farmersmarkets/v1/data.svc/zipSearch?zip=60629').then(function(response){
return (response.data.results || []).map(function(itm){return {id:itm.id, name:itm.marketname}}); //map your data
});
Demo
来源
2014-09-19 01:58:49
PSL