2016-11-04 63 views
0

以下是我的HTML, 我想将以下参数传递给数据库。我可以传递简单的文本值。但不能在选项标签中传递必需的参数。当我打电话后呼叫,动态选项的选择,它是从主机表发送主机的所有数据,但我想从选定的选项只需要通过选择的“选项”数据

<form name="main" novalidate> 
    <div class="table-responsive" ng-show="visible8"> 
    <h4>Conditions</h4> 
    <!-- <button type="button" class="btn btn-primary" ng-click="addCondition()">Apply</button> --> 
    <button type="button" class="btn btn-primary" ng-click="addNewCondition()">Add Condition</button> 
    <button type="button" class="btn btn-primary" ng-click="removeCondition()">Remove Condition</button> 
    <button type="button" class="btn btn-primary" ng-click="cancel()">Cancel</button> 
    <button class="btn btn-primary pull-right" ng-click="showAction()" ng-disabled!="">Next Step</button>         
    <button class="btn btn-primary pull-right" ng-click="showBackRules()" ng-disabled!="">Back</button>         
    <br> 
    <br> 
    <fieldset data-ng-repeat="choice in choices"> 
     <table class="table table-bordered" id="table" > 
     <thead> 
      <tr> 
      <th>Parameter</th> 
      <th>Value</th> 
      <th>Comment</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
      <th>Select Condition Type</th> 
      <td> 
       <select name="option" class="form-control" ng-model="mySelect" ng-disabled="readonly" ng-change="selectedOption(mySelect);displayParam()"> 
       <option ng-repeat="type in model.condition_type" value= "{{ type.NAME }}" >{{ type.NAME }}</option> 
       </select> 
      </td> 
      <td>Select Condition</td> 
      </tr> 
      <tr ng-repeat="child in model.rule_key[$index]"> 
      <!-- <td ng-repeat="child in parent_rule"> 
       {{ child.KEY_NAME }} 
       </td> 

       </tr> --> 
      <th> {{ child.KEY_NAME }} </th> 
      <td> 
       <input type="text" class="form-control" ng-model="rule1.conditions.Value" 
       name="child.KEY_NAME" ng-if="child.KEY_NAME != 'Host' && child.KEY_NAME != 'Sensor' && child.KEY_NAME != 'Field' && child.KEY_NAME != 'Operator'" required/> 
       <span style="color:red" ng-show="main.AssetURL.$error.required ">Service name</span> 
       <select name="child.KEY_NAME" class="form-control" 
       ng-options="host.Name for host in hosts track by host.id" 
       ng-model="rule1.conditions.Host" ng-if="child.KEY_NAME != 'Operator' && child.KEY_NAME != 'Sensor' && child.KEY_NAME != 'Field' && child.KEY_NAME != 'Value'" ng-disabled="readonly"> 
       <option value=""></option> 
       </select> 
       <select name="child.KEY_NAME" class="form-control" 
       ng-options="sensor.SnsName for sensor in model.sensors" 
       ng-model="rule1.conditions.Sensor" ng-if="child.KEY_NAME != 'Operator' && child.KEY_NAME != 'Host' && child.KEY_NAME != 'Field' && child.KEY_NAME != 'Value'" ng-disabled="readonly"> 
       <option value=""></option> 
       </select> 
       <select name="child.KEY_NAME" class="form-control" ng-model="rule1.conditions.Operator" 
       ng-if="child.KEY_NAME != 'Host' && child.KEY_NAME != 'Sensor' && child.KEY_NAME != 'Field' && child.KEY_NAME != 'Value'" required> 
       <option value="greater">></option> 
       <option value="smaller"><</option> 
       <option value="equal">=</option> 
       </select> 
       <span style="color:red" ng-show="main.CaptLen.$error.required ">Select ServiceType</span> 
       <select name="child.KEY_NAME" ng-if="child.KEY_NAME != 'Host' && child.KEY_NAME != 'Sensor' && child.KEY_NAME != 'Operator' && child.KEY_NAME != 'Value'" class="form-control" ng-model="rule1.conditions.Field" ng-disabled="readonly" > 
       <option ng-repeat="field in ruleField[0].columns track by $index" value= "{{ field }}" >{{ field }}</option> 
       </select> 
      </td> 
      <td> {{ child.DESCRIPTION }} </td> 
      </tr> 
     </tbody> 
     </table> 
    </fieldset> 
    </div> 
</form> 

各自JS

$scope.saveAll = function(rule1) { 
    console.log(rule1); 
    var newaction = JSON.stringify(rule1.actions); 
    console.log("newaction", newaction); 
    var newcondition = JSON.stringify(rule1.conditions); 
    console.log("newcondition", newcondition); 
    var newrule = { 
     ruleName: rule1.ruleName, 
     ruleDesc: rule1.ruleDesc, 
     RULE_TYPE: rule1.RULE_TYPE, 
     CONDITION_LIST: newcondition, 
     ACTION_LIST: newaction, 
    }; 
    console.log("newrule", newrule); 

    $http.post("/nodejs/addRule", newrule) 
     .success(function(data) { 
      console.log("New rule", data); 
      $scope.model.rule_list.push(data[0]); 
      $scope.len = $scope.model.rule_list.length; 
     }) 
     .error(function(err) { 
      alert("error"); 
      //console.log(err); 
     }); 
    // $scope.check(); 
    $scope.visible13 = false; 
    $scope.visible2 = true; 
    $scope.visible3 = true; 
    $scope.visible7 = true; 
    $scope.rule1 = {}; 
}; 
只传递主机名

output Input screen

+0

您能否创建演示代码.. –

+0

对不起,我不了解你 –

+0

在小提琴或plnkr中创建演示 –

回答

0

您应该绑定的主机的唯一名称使用NG选项语法像这样NG-型号:

ng-options="host.Name as host.Name for host in hosts track by host.id"