将值设置为AngularJS中的多个<select>标记

时间:2017-04-15 09:44:15

标签: angularjs json

我试图将值设置为多个&lt; select&gt;标签如下图所示。 &LT;选择&GT;标签没有被选中,一切看起来都很好。 我错过了什么? HTML: &lt; tr ng-repeat =&#34; t在标签跟踪中由$ ​​index&#34;&gt; &lt; td&gt; {{$ index + 1}}&lt; / td&gt; &lt; td&gt; {{t.name}}&lt; / td&gt; &lt; td&gt; {{t.phno}}&lt; / td&gt; &lt; td&gt; {{t.email}}&lt; / td&gt; &lt; td&gt; {{t.type}}&lt; / td&gt; &lt; td data-ng-show =&#34; user_type ==&#39; student&#39; || user_type ==&#39; all&#39;&#34;&gt; {{t.class_name}}&lt; / td&gt; &lt; td data-ng-show =&#34; user_type ==&#39; student&#39; || user_type ==&#39; all&#39;&#34;&gt; {{t.section_name}}&lt; / td&gt; &lt; td data-ng-show =&#34; user_type ==&#39; student&#39; || USER_TYPE ==&#39;所有&#39;&#34;&GT;     &lt; select data-ng-show =&#34; t.type ==&#39;学生&#39;&#34; NG-模型=&#34; plan_id的数据类型&#34;&GT;         &lt; option value =&#39;&#39;&gt; - SELECT - &lt; / option&gt;         &lt; option ng-repeat =&#34; priceList&#34;中的价格data-ng-selected =&#34; {{t.plan_id == price.plan_id}}&#34;值=&#34; {{price.plan_id}}&#34;&GT; {{price.plan_name}}&LT; /选项&GT;     &LT; /选择&GT; &LT; / TD&GT; &lt; td data-ng-show =&#34; msg ==&#39;&#39;&#34;&gt;&lt; input type =&#34; checkbox&#34;数据-NG-模型=&#34; t.selected&#34;值=&#34; {{t.id}}&#34;数据-NG核对=&#34;萨勒&#34;&GT;&LT; / TD&GT; &lt; td data-ng-show =&#34; msg ==&#39; r&#39;&#34;&gt; {{t.status}}&lt; / td&gt; &lt; td data-ng-show =&#34; user_type ==&#39; student&#39; || USER_TYPE ==&#39;所有&#39;&#34;&GT;     &lt; button type =&#34; button&#34;数据-NG出现=&#34; t.type ==&#39;学生&#39;&#34; ng-click =&#34; updatePlan(plan_id,t.id);&#34;&gt;更新&lt; / button&gt; &LT; / TD&GT; JS:     $ scope.pricingList = [{&#34; plan_id&#34;:1,&#34; plan_name&#34;:&#34; Free&#34;},{&#34; plan_id&#34;:2,& #34; PLAN_NAME&#34;:&#34;具有基本&#34;}];     var URL = appURL +&#39; /adm/loadSMSCollege.do' ;;     var json = {&#34; type&#34;:$ scope.user_type,&#34; class_id&#34;:$ scope.class_id,&#34; section_id&#34;:$ scope.section_id,&#34; CREATED_BY&#34;:$ cookieStore.get(&#34; loginBean&#34)CREATED_BY};。     $ http.post(URL,JSON.stringify(json))。then(function(response){         $ scope.tab = response.data;         $ scope.len = response.data.length;     }); 示例视图:

1 个答案:

答案 0 :(得分:2)

试试这个。使用ng-options代替ng-repeat也可以将模型更改为t.plan_id

 <td data-ng-show="user_type=='student' || user_type=='all'">
   <select data-ng-show="t.type=='Student'" ng-model="t.plan_id" ng-options="price.plan_id as price.plan_name for price in pricingList">
      <option value=''>--SELECT--</option>

</select>
 </td>