所以我有一个 mongodb 数据库,其中包含多个部门名称。我想从我的 nodejs 服务器 http.get() 名称。从那以后,我想将名称填充到选择框中。这个问题的重要部分不是node/mongo部分,而是js/html部分,我有来自get的响应,如何将它放入选择框?这是我的代码:
部分代码:
$http.get('http://localhost:8000/getData').then(function(response) {
// code to place here
});
以及 html 部分:
<select placeholder="Select a User">
<option ng-model="selectUser"></option>
</select>
最佳答案
首先,您必须将响应对象中的数据放入 Controller 属性中,如下所示:
$http.get('http://localhost:8000/getData').then(function(response) {
$scope.options = response.data;
});
然后您可以使用 Angular 中的 ng-options 指令来使用如下值填充选择框:
<select placeholder="Select a User" ng-model="selectUser" data-ng-options="option.Member for option in options">
</select>
关于javascript - 使用 Nodejs 信息填充选择框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39349821/