问题描述:

I have a mysql table. Table schema is -

table_categories - category_id, category_name

This is my perl cose to get the data from the taable and convert it into json format.

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;

I am trying to fill "select" in HTML using 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>

The problem is data is getting filled, but the category_id assigned to "option" value is in sequence , i.e. 1,2,3,4. I want actual category_id to be assigned to option value.

What is missing here. Can anyone please help me on this.

网友答案:

Inside your select tag you need the following:

<option ng-repeat="item in itemsReturnedFromYourAjaxCall" value="item.id">{{ item.name }}</option>
相关阅读:
Top