AngularJS Typeahead显示对象



我正试图让我的应用程序在我的一个视图中拥有一个typeahead控件。目前,我已经将其设置为与此示例完全相同:

http://plnkr.co/edit/5kGZkNPZ7rIFfb4Rvxej?p=preview

但为了满足我的需求,我必须让它在下拉列表中显示整个对象。我的数组看起来有点像:

self.tests = [
    {
        "detail": "27/06/2015, 1 Lines, £478.40",
        "title": "HOM026MA01|ww06-1526",
        "type": "O",
        "value": "W0669090"
    },
    {
        "detail": "25/06/2015, 3 Lines, £1390.92",
        "title": "BER0050000|andrew02",
        "type": "O",
        "value": "W0667777"
    }
];

所以我把我的html改成了这个:

<input type="text" placeholder="Search" ng-model="controller.selected" typeahead="stuff as stuff.value for stuff in controller.tests | filter:$viewValue" />

正如您所看到的,这将显示json对象的,但我希望它也显示其他细节。有人知道你是怎么做到的吗?

您可以在这里简单地使用字符串串联

<input type="text" placeholder="Search" 
  ng-model="controller.selected" 
  typeahead="stuff.value + ' ' + stuff.title + ' '+  stuff.detail for stuff in controller.tests | filter:$viewValue" />

Demo Plunkr

最新更新