我發現這個代碼可以像我想要的那樣工作,但我需要過濾對象上的Name屬性並在選中時顯示對象屬性。我分了這個。 http://jsfiddle.net/sebmade/swfjT/對象上的自動完成
我的嘗試...那是行不通的。這可能很簡單。是不是總是。欣賞別人的眼睛來弄明白這一點。 https://jsfiddle.net/lnbailey/7py3rbgh/2/
<div ng-app='MyModule'>
<div ng-controller='autocompleteController'>
<input auto-complete ui-items="trans" ng-model="selected"> Name = {{selected}}
<div ng-repeat="name in names">
<div ng-if="selected == name">
{{selected.Name}}<br>
{{selected.Address}}<br>
{{selected.City}} <br>
{{selected.State}} <br>
{{selected.Zip}}
</div>
</div>
</div
function DefaultCtrl($scope) {
$scope.names = [{
'id': 1,
'Name': 'Transporter 1',
'Address': '1 Transporter Address',
'City': "Nashville",
'State': 'TN',
'Zip': "10001",
}, {
'id': 2,
'Name': 'Transporter 2',
'Address': '2 Transporter Address',
'City': "Nashville",
'State': 'TN',
'Zip': "10001",
}, {
'id': 3,
'Name': 'Transporter 3',
'Address': '3 Transporter Address',
'City': "Nashville",
'State': 'TN',
'Zip': "10001",
}, {
'id': 4,
'Name': 'Transporter 4',
'Address': '4 Transporter Address',
'City': "Nashville",
'State': 'TN',
'Zip': "10001",
}, {
'id': 5,
'Name': 'Transporter 5',
'Address': '5 Transporter Address',
'City': "Nashville",
'State': 'TN',
'Zip': "10001",
}
];
$scope.trans = [];
angular.forEach($scope.names, function(name) {
$scope.trans.push(name.first);
});
};
angular.module('MyModule', []).directive('autoComplete', function($timeout) {
return function(scope, iElement, iAttrs) {
iElement.autocomplete({
source: scope[iAttrs.uiItems],
select: function() {
$timeout(function() {
iElement.trigger('input');
}, 0);
}
});
};
});
是啊。我發現這個解決方案,它確實很好。但是,這個項目不能有引導。感謝您的建議。 – user7704329