2016-01-05 40 views
0

與NG-選項AngularJS填充選擇使用JSON從JSON下拉選項,使用angularjs數據類型被附加

<select id="routeName-{{$index}}" ng-model="row.routeName" ng-options="routeName.id as routeName.name for routeName in routeNames" ng-change="flowRootChange($index)" style="width: 115px;"></select> 

輸入JSON低於:

scope.routeNames=[{"id":"1","name":"routeName1"},{"id":"2","name":"routeName2"}]; 

但在HTML顯示像下面:

<select style="width: 115px;" ng-change="flowRootChange($index)" ng-options="routeName.id as routeName.name for routeName in routeNames" ng-model="row.routeName" id="routeName-0" class="ng-pristine ng-valid ng-touched"> 
    <option label="routeName1" value="string:1">routeName1</option>  
    <option label="routeName2" value="string:2">routeName2</option> 
</select> 

通過使用JQuery讀取數據,我得到了string:2作爲輸出。

console.log($("#routeName-"+rowid +" :selected").val()); 

我不能使用ng-model/$scope.row.routeName因爲這個下拉是表。 如何在不使用split()方法的情況下讀取選定的值(不帶string:)? 我正在使用'AngularJS v1.4.8'varsion。

+0

您還可以使用: 'ng-options =「routeName as routeName.name for routeName in routeNames track by routeName.id」' –

+0

@SujataChanda這是填充選項很好,但選擇的值不設置,下面的方法是workin g我接受了。 –

回答

1

可以使用NG-重複,而不是NG選項

<select style="width: 115px;" ng-change="flowRootChange($index)" ng-model="row.routeName" > 
    <option ng-repeat='routeName in routeNames' label="routeName{{ routeName.id }}" value="{{ routeName.id }}">{{ routeName.name }}</option> 
</select> 
+0

'{{routeName.name}}}}'這是正確的嗎? –

+0

現在它的正確@Rajesh –

-2

檢查這一項: -

<select style="width: 115px;" ng-change="flowRootChange($index)" ng-model="name" > 

{{routeName.name}}

+0

請把詳細的答案。 –

相關問題