我有一個mysql表。表架構是 -如何使用anjular.js分配id來選擇選項值
table_categories - category_id, category_name
這是我的perl cose從taable獲取數據並將其轉換爲json格式。
my $sql_query = "SELECT * from table_categories order by category_name";
my $statement = $db_handle->prepare ($sql_query) or die "Couldn't prepare query '$sql_query': $DBI::errstr\n";
$statement->execute() or die "SQL Error: $DBI::errstr\n";
my @loop_data =();
my $count = 0;
while (my @data = $statement->fetchrow_array())
{
push(@loop_data, \@data);
$count++;
}
my $json;
$json->{"entries"} = \@loop_data;
$json->{"count"} = $count;
print to_json($json);
$db_handle->disconnect;
我試圖用angular.js
<select ID="select-add-new-product-catty-name" ng-model="selectedItem" ng-options="category[0] as category[1] for category in categories.entries"></select>
的問題是數據是越來越填入HTML填寫「選擇」,但分配到「選項」值CATEGORY_ID是按順序排列,即1,2,3,4。我想要將實際的category_id分配給選項值。
這裏缺少什麼。任何人都可以請幫我。
您應該檢查這個http://stackoverflow.com/questions/12139152/how-to-set-value-property-in-angularjs-ng -options – 2014-11-23 02:37:44