Javascript 使用AngularJS和RubyonRails从数据库中下拉数据

Javascript 使用AngularJS和RubyonRails从数据库中下拉数据,javascript,ruby-on-rails,angularjs,ruby,erb,Javascript,Ruby On Rails,Angularjs,Ruby,Erb,我正在尝试制作一个下拉列表,以获取在RubyonRails项目中使用AngularJS从DB加载的当前站点 我有dashboard.html.erb和SitesController.js <div class="row" ng-controller="SiteIndexController"> <select ng-model="selectedName" ng-options="x for x in names"> <option ng-repeat="x

我正在尝试制作一个下拉列表,以获取在RubyonRails项目中使用AngularJS从DB加载的当前站点

我有dashboard.html.erb和SitesController.js

<div class="row" ng-controller="SiteIndexController">

<select ng-model="selectedName" ng-options="x for x in names">
  <option ng-repeat="x in name" value="{{x.name}}">{{x.name}}</option>
</select>

</div>
$scope.sites=response.data.content将站点添加到其中。我想从中得到SITE_NAME值,并将其放在下拉列表中


当我将其从名称更改为站点时,它是空的。从$scope.sites返回站点名称需要什么?

您应该只使用
ng options
,而不是
ng options
ng repeat
。请参阅。您应该只使用
ng选项
,而不是
ng选项
ng重复
。看见
angular.module('MetronicApp')
  .controller('SiteIndexController', ["$rootScope", "$scope", "$http", "$timeout", "$state",
    function($rootScope, $scope, $http, $timeout, $state) {

      $scope.names = ["Name1", "Name2", "Name3"];

      $scope.$on('$viewContentLoaded', function() {
        // initialize core components

        $scope.sites = [];
        $scope.selected = $scope.sites.name

        $scope.getSites = function(){
          $http.get("/sites").then(
            function success(response){
              $scope.sites = response.data.content;

              $scope.selected = $scope.sites
              $scope.selectpicker = $scope.sites.name
            },
            function failure(response, status) {
              alert("Something went wrong! - index");
            }
          )
        };

        $scope.getSites();
    });
}])