2015-12-03 99 views
1

我有這樣的代碼:angularjs - 動態NG-模型

<!----> 
<div ng-repeat="priority in toppriorities"> 
    <table> 
    <tr> 
    <td>{{priority}}.</td> 
    <td> 
    <table> 
     <tr> 
     <td> 
     <select name="singleSelect" ng-model="APME" ng-change="changedValue(APME,priority)" > 
     <option ng-repeat="me in mainelements" value="{{me.Recomendation}}">{{me.Title}}</option> 
     </select> 
     </td> 
     <td> 
     <div ng-model="APMER[priority]">{{APMER[priority]}}</div> 
     </td> 
     </tr> 
    </table> 
</div> 

我想更新ng-model``APMER[priority]我選擇之後,從APME東西更新:

//JS 
$scope.changedValue=function(i, priority){ 
     $scope.APMER[priority] = i; 
    } 
  1. 我有點不能讓ng-model="APMER[priority]"上班。
  2. in js - ng-model="APMER[priority]",什麼是分配動態變量的正確方法?

回答

0

你需要做這樣的事情。

<div ng-app ng-controller="QuestionController"> 
    <ul ng-repeat="question in Questions"> 
     <li> 
      <div>{{question.Text}}</div> 
      <select ng-model="Answers[question.Name]" ng-options="option for option in question.Options"> 
      </select> 
     </li> 
    </ul> 

    <a ng-click="ShowAnswers()">Submit</a> 
</div> 

http://jsfiddle.net/DrQ77/

,讓你把一個模型中的JavaScript表達式。