gpt4 book ai didi

mysql - angularjs 如何从 mysql 中检索数据并在 ng-select 和 ng-options 中显示

转载 作者:行者123 更新时间:2023-11-29 06:25:37 25 4
gpt4 key购买 nike

我试图使用 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>

最佳答案

你需要使用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>

关于mysql - angularjs 如何从 mysql 中检索数据并在 ng-select 和 ng-options 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31161478/

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