试图使用AngularJS从ES短语建议程序的Recommendations对象显示options数组中的前10个选项,但显示为树桩...。
这将输出options数组中的第一个元素:
{{suggestions.options[0].text}}
文字是实际的建议。
Chrome中的开发者控制台的输出:
suggest: {,…}
phraseSuggestion: [{text: "pytho", offset: 0, length: 5, options: [{text: "python", score: 0.12858662}]}]
0: {text: "pytho", offset: 0, length: 5, options: [{text: "python", score: 0.12858662}]}
length: 5
offset: 0
options: [{text: "python", score: 0.12858662}]
0: {text: "python", score: 0.12858662}
text: "pytho"
我如何访问:
options: [{text: "python", score: 0.12858662}]
在我的HTML模板中,并显示数组中的前5到10个选项。
因此,例如,如果您具有这样的JSON输出,并且想要显示前2个选项,则可以执行以下操作:
HTML:
<div ng-app="myApp" ng-controller="dummy">
<p ng-repeat="option in out.options | limitTo:2">{{option.text}} - {{option.score}}</p>
</div>
JS:
angular.module('myApp', [])
.controller('dummy', ['$scope', '$sce', function ($scope, $sce) {
$scope.out = {
"options": [{
"text": "python",
"score": 0.12858662
}, {
"text": "linux",
"score": 0.12858662
}, {
"text": "php",
"score": 0.12858662
}, {
"text": "js",
"score": 0.12858662
}, {
"text": "java",
"score": 0.12858662
}]
};
}]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句