我似乎無法在下拉菜單中顯示cause - description
,而是顯示[object Object]
。選擇它時,我想選擇cause
。這怎麼能實現?AngularJS「對象」顯示但不是實際模型
萬一片段無法查看,這裏的plunker:https://plnkr.co/edit/0jXmzfE6lsdTY5anzn9y?p=preview
我的標記:
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TypeaheadCtrl', function($scope, $http) {
\t var url = 'https://spreadsheets.google.com/feeds/list/1O7M5gaEGlyE5gkOBARJrxJJMBYiTwz2THVjgbaTx9v8/od6/public/values?alt=json';
var parse = function (entry) {
console.log(entry);
var description = entry.gsx$description.$t;
var cause = entry.gsx$cause.$t;
return {
description: description,
cause: cause
};
};
$http.get(url)
.then(function (response) {
var entries = response.data.feed.entry;
$scope.parsedEntries = [];
for (var key in entries) {
var content = entries[key];
$scope.parsedEntries.push(parse(content));
\t \t \t \t
\t \t \t \t \t }
});
});
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
<script src="example.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class='container-fluid typeahead-demo' ng-controller="TypeaheadCtrl">
<h4>Static arrays</h4>
<pre>Model: {{selected | json}}</pre>
<input type="text" ng-model="selected" typeahead-editable="false" uib-typeahead="cause for cause in parsedEntries | filter:$viewValue | limitTo:8" class="form-control">
</div>
</body>
</html>
在此先感謝!