Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在angular js中设置选定的特定选项。记录来自数据库_Html_Angularjs - Fatal编程技术网

Html 如何在angular js中设置选定的特定选项。记录来自数据库

Html 如何在angular js中设置选定的特定选项。记录来自数据库,html,angularjs,Html,Angularjs,我对angularJs有意见。我想要一个下拉列表来选择编辑记录期间的选项。我是angularJs的新手,请帮我做这件事 HTML代码 <select class="form-control" id="txtCities" ng-model='selected' ng-options="c.city_id as c.city_name for c in storesCities"> <option></optio

我对angularJs有意见。我想要一个下拉列表来选择编辑记录期间的选项。我是angularJs的新手,请帮我做这件事

HTML代码

<select class="form-control" id="txtCities" ng-model='selected' 
       ng-options="c.city_id as c.city_name for c in storesCities">
                    <option></option>
</select>
Ajax响应如下所示:

{"data":[{"city_id":410115,"city_name":"Angulo"},{"city_id":410210,"city_name":"india"}

{"city_id":410220,"city_name":"pune"},{"city_id":412830,"city_name":"Delhi"}],"pages":1,"page":"1","result":"OK","message":""}

只是改变了一下

 $scope.selected=410210;

请在html的脚本文件中添加这个js文件,你可以在过滤器中使用它

       Underscore.js
       http://plnkr.co/edit/8B7vVgT7zU3I1VhrO82I?p=info

       $scope.selectedCityId = '410210';

       $http.get('StoreCitiesData', {
            params: {
                pageNumber: page
            }
       }).then(function(response) {
            $scope.storesCities = response.data.data;
            $scope.selected = 
                  _.filter($scope.storesCities, function (city) {
                      return city.city_id == $scope.selectedCityId;             
                  });
       });
我们可以使用angular.foreach代替filter

       $scope.selectedCityId = '410210';

       $http.get('StoreCitiesData', {
            params: {
                pageNumber: page
            }
       }).then(function(response) {
            $scope.storesCities = response.data.data;
            $scope.selected = 

                  angular.forEach($scope.storesCities, function(city) {
                    if(city.city_id == $scope.selectedCityId)
                    {
                      return city;
                    }
                  });

       });

你到底想达到什么目的?嗨,我做过的每个人。。谢谢你的答复。。
       $scope.selectedCityId = '410210';

       $http.get('StoreCitiesData', {
            params: {
                pageNumber: page
            }
       }).then(function(response) {
            $scope.storesCities = response.data.data;
            $scope.selected = 

                  angular.forEach($scope.storesCities, function(city) {
                    if(city.city_id == $scope.selectedCityId)
                    {
                      return city;
                    }
                  });

       });