gpt4 book ai didi

javascript - 将 ng-options 与响应对象一起使用

转载 作者:行者123 更新时间:2023-11-30 12:26:08 25 4
gpt4 key购买 nike

我看过很多关于如何使用 ng-options 的答案,但还没有找到解决方案或正确的方法。

我的代码很简单。我想遍历收到的响应对象并使用名称属性填充“选择”标签的“选项”。

索引.js

app.controller("promo", function($scope, $http) {

$scope.behaviors = {};

$scope.init = function() {
return $http.get('/behaviors').then(function(response) {
$scope.behaviors = response.data;
console.log(typeof($scope.behaviors))
})
}

我的回复是这样的

Object {bangalore.yml: Object, ean.yml: Object, chennai.yml: Object}

我以为我可以像这样用 ng-repeat 做到这一点

<select ng-model="behavior" ng-repeat="behavior in behaviors">
<option>{{behavior.name}}</option>

我是初学者,我需要知道该做什么以及 ng-options 的真正工作原理。

最佳答案

使用:-

 <select ng-model="behavior" ng-options=" value.name for (key, value) in behaviors">

</select>

Plunker

关于javascript - 将 ng-options 与响应对象一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29333024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com