如何使用ng-if用于嵌套的对象数组

时间:2017-02-07 00:10:56

标签: javascript angularjs angularjs-ng-repeat

doc.html

<tr data-ng-repeat="childCondition in model.rule_key[$index]">
    <th> {{ childCondition.KEY_NAME }} </th>
    <td>
    <input type="text" class="form-control" ng-model="rule1.childCondition[$parent.$parent.$index][childCondition.KEY_NAME]"
                                                 name="childCondition.KEY_NAME"  ng-if="childCondition.KEY_NAME == 'Value'" required/>
                                                 <span style="color:red" ng-show="main.AssetURL.$error.required ">Service name</span>

                                                 <select name="childCondition.KEY_NAME" class="form-control" 
                                                 ng-options="host.Name as host.Name for host in hosts" 
                                                 ng-model="rule1.childCondition[$parent.$parent.$index][childCondition.KEY_NAME]"ng-if="childCondition.KEY_NAME == 'Host'" ng-disabled="readonly">
                                                 <option value=""></option>
                                                 </select>


                                              </td>
                                              <td> {{ childCondition.DESCRIPTION }} </td>
                                            </tr>

doc.js

var newcondition = JSON.stringify(rule1.childCondition);

当前输出

newcondition = [{"Value":"TEST", "Host":"TEST"}, {"Value":"TEST1", "Host":"TEST1"}]

但我希望以下形式的json输出(嵌套的对象数组)

预期输出为:

 [
      {
       "Trigger":"Auto",
       "Condition":[
        {"Value":"TEST", "Operator":"=", "Host":"TEST"},
        {"Value":"TEST1", "Operator":"=", "Host":"TEST1"}
                ]
      }
    ]

0 个答案:

没有答案