【发布时间】:2020-07-01 08:35:43
【问题描述】:
我正在使用 NgBootstrap TypeAhead 在表单中集成查找。我有items json 如下:
type Item = {name: string, description: string};
const items:Item[] = [
{"name":"NAME-1", "description":"Description -1"},
{"name":"NAME-2", "description":"Description -2"},
]
并有一个格式化程序,例如:
formatter = (item: Item) => {
return item.name;
}
对于我添加的 HTML:
<input
id="typeahead-focus"
type="text" [formControlName]="idx"
(selectItem)="selectedItem($event, idx)"
[ngbTypeahead]="ItemSearch"
[inputFormatter]="formatter"
[resultFormatter]="formatter"
[editable]='false'
/>
它工作正常,但我在提交表单时遇到了一个问题。我只需要name 索引作为输入字段的值。但它正在提交不需要的完整 JSON 对象。如何解决这个问题?
【问题讨论】:
-
你能添加一个最小可重现的 sn-p 吗?
标签: javascript angular typescript ng-bootstrap typeahead