我正在实现一个剑道下拉菜单,并在用户尝试通过输入字符进行搜索时尝试调用api。我可以看到正在对api进行调用,并且api返回了过滤后的值,但是数据没有被绑定。
我可以看到发生了错误,并执行了err块。错误指出
解析http://localhost:54455/fund/HFRFundSearch?term=as时Http失败
有人可以告诉我问题是什么。是因为api返回了一个对象
这是我的代码
<label for="inputFax" class="col-md-2 col-form-label header">Third Party Database Feed</label>
<div class="col-md-3">
<div *ngIf="!EditMode">{{FundDetails.HFRFundName}}</div>
<kendo-dropdownlist style="width:350px" [(ngModel)]="HFRFunds" [data]="HFRFunds" [filterable]="true" [valuePrimitive]="true" textField="text" valueField="id" (filterChange)="handleFilter($event)"></kendo-dropdownlist>
</div>
组件
handleFilter(value) {
if (value.length >= 2) {
this.fundService.getHFRFund(value)
.subscribe(data => {
this.HFRFunds = data;
},
err => {
this.Error = 'An error has occurred. Please contact BSG';
},
() => {
});
}
}
服务
constructor(
private http: HttpClient,
private config: AppConfig)
{ }
getHFRFund(value : string) {
let pars = new HttpParams();
pars = pars.append('term', value.toString());
const url = this.config.api.hfrFundSearch;
return this.http.get(url, { params: pars, withCredentials: true });
}
api。
[HttpGet]
[AuthorizationLevel(AuthAccessLevel.Read)]
public object HFRFundSearch(string term)
{
try
{
var hfrFunds = new List<object>();
if (!string.IsNullOrEmpty(term))
{
term = term.ToLower();
hfrFunds.AddRange(GetViewService<V_HFR_FUND>()
.Where(x => x.HFR_FUND_NAME.ToLower().StartsWith(term))
.Take(10)
.OrderBy(x => x.HFR_FUND_NAME)
.Select(x => new { id = x.HFR_FUND_ID, text = x.HFR_FUND_NAME })
.ToList());
}
return hfrFunds;
}
catch (Exception ex)
{
_logger.Error(ex);
return ex;
}
}
答案 0 :(得分:0)
// API
[HttpGet]
[AuthorizationLevel(AuthAccessLevel.Read)]
public object HFRFundSearch(string term)
{
try
{
var hfrFunds = new List<object>();
if (!string.IsNullOrEmpty(term))
{
term = term.ToLower();
hfrFunds.AddRange(GetViewService<V_HFR_FUND>()
.Where(x => x.HFR_FUND_NAME.ToLower().StartsWith(term))
.Take(10)
.OrderBy(x => x.HFR_FUND_NAME)
.Select(x => new { value = x.HFR_FUND_ID, text = x.HFR_FUND_NAME })
.ToList());
}
return hfrFunds;
}
catch (Exception ex)
{
_logger.Error(ex);
return ex;
}
}
// component
// component
import { map } from 'rxjs/operators';
handleFilter(value) {
if (value.length >= 2) {
this.fundService.getHFRFund(value).subscribe(
data => {
this.HRFunds = data;
});
}
}