1

我试图使用 ng-select 和 ng-options 以 html 形式填充数据。但无法弄清楚。我的代码如下所示:

function get_areanames() {    
$qry = mysql_query('SELECT * from tbl_area');
$data = array();
while($rows = mysql_fetch_array($qry))
{
    $data[] = array(
                "areaid"            => $rows['areaid'],
                "areaname"     => $rows['areaname']
                );
}
print_r(json_encode($data));
return json_encode($data);  

}

$scope.get_areanames = function($scope,$http){
 $http.get("library/function.php?action=get_areanames").success(function(data)
{
   $scope.areaname = data;  


});
}

<select class="form-control select2me" data-placeholder="Choose Area Name" name="areaname"  ng-model="areaname" required> <option></option></select>
4

2 回答 2

1

您需要使用ng-options,请考虑:

<select ng-options="item.areaid as item.areaname for item in areaname track by item.areaid"
        ng-model="selectedArea"
        class="form-control select2me"
        name="areaname"
        required>
     <option value="">Choose Area Name</option>
 </select>
于 2015-07-01T12:39:13.963 回答
1

您需要将 ng-options 属性添加到您的选择中:

<select ng-options="areaitem.areaname for areaitem in areaname" ....

这将从您的范围内的 areaname 数组中填充选项。

于 2015-07-01T12:40:32.527 回答