真的很简单的问题,但是我怎样才能设置typeahead在一个不同于我的typeahead的表中工作的表中工作?表中的角度UI-Bootstrap typeahead
例如,我在表中有一个外键,并且我想让用户根据外键的主表中相应的NAME值选择此键。
代码示例:
<table class="table table-bordered table-hover table-striped rwd-table" id="page-wrap">
<thead>
<tr>
<th>Primary ID</th>
<th>Foreign Key (As Name)</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="p in PrimaryTable" id="display">
<td data-th="ID">{{p.PrimaryID}}</td>
<td>
<input id="ForeignKeyName"
type="text"
ng-model="p.ForeignKeyID"
uib-typeahead="f.ForeignKeyID as f.ForeignKeyName for f in ForeignKeyTable | filter:$viewValue"
class="form-control">
</td>
</tr>
</tbody>
有了这个例子,我希望用户能够看到“外键(如姓名)”作为名称值而不是ID值。诀窍是,我还希望底层的价值是ID,并将其映射为与ng模型通知的原始值相匹配。
更新:另一个问题是,我已经符合前一个是如何设置我的ng模型来显示ForeignKeyTable.ForeignKeyName
代替PrimaryTable.ForeignKeyID
?
这将是类似的(我想象)如何uib类型的头匹配ForeignKeyTable.ForeignKeyID
和ForeignKeyTable.ForeignKeyName
但与两个独立的表?
我会的愿望就是能够把ng-model: PrimaryTable.ForeignKeyID as ForeignKeyTable.ForeignKeyName
我不”真正理解这个概念在这里。你能分享一些存储在'PrimaryTable'和'ForeignKeyTable'中的样本数据吗?它们是以某种方式相关的吗? – nocodename
基本主表包含一个链接到ForeignKeyTable的标识ID列的列。换句话说,从PrimaryTable行可能是{ID:1,ForeignKeyID:18,...}和相应的行ForeignKeyTable可能是{ForeignKeyID:18,ForeignKeyName: '苹果',...}。有了这些数据,我基本上希望用户能够输入/选择“苹果”和相应的值,该表的用途应为18 – Austin
,但是这应该是18从'PrimaryTableRow.ForeignKeyID'或'ForeignKeyTableRow.ForeignKeyID值'? – nocodename