使用预先输入存储与显示不同的存储

时间:2015-09-22 22:25:06

标签: angularjs twitter-bootstrap

我正试图为供应商实施规范的先行模式。我们有供应商名称和供应商ID。我想在下拉列表中显示{name} - {ID},在文本框中显示{name},但在模型中存储{id}。这可能,我该怎么做?

我的尝试:

 <input id="toSupplier" type="text" ng-model="selectedToSupplier"
                   placeholder="Enter a to supplier name"
                   class="form-control"
                   typeahead="supplier.name as (supplier.name + ' - ' + '[' +  supplier.id + ']') for supplier in getToSuppliers($viewValue)"
                   typeahead-min-length="2"
                   typeahead-loading="Loading" />

这给了我在下拉列表中想要的内容,但是模型和文本框中的名称。我想在模型中使用id。

1 个答案:

答案 0 :(得分:0)

尝试:供应商而不是supplier.name

 <input id="toSupplier" type="text" ng-model="selectedToSupplier"
                   placeholder="Enter a to supplier name"
                   class="form-control"
                   typeahead="supplier as (supplier.name + ' - ' + '[' +  supplier.id + ']') for supplier in getToSuppliers($viewValue)"
                   typeahead-min-length="2"
                   typeahead-loading="Loading" />