0

我想从服务中获取 json 数组数据,然后在表中显示此数据(带有复选框),然后我想获取数据(由用户检查,我的意思是单击了复选框)并将其放入另一个 json 数组,然后包装这个变量作为 camVariable 为了将其导出为第二个用户表单,我已经尝试了多种方法但无法实现我的目标,我应该改变什么才能使它成为可能?这是我的代码:

camForm.on('form-loaded', function() {

      camForm.variableManager.fetchVariable('jsonData');
    });
    camForm.on('variables-fetched', function() {
      $scope.jsonData = camForm.variableManager.variableValue('jsonData');
    });

var  selectedDocuments=$scope.selectedDocuments=[];
 $scope.content = '';

 $scope.isChecked = function(id){
      var match = false;
      for(var i=0 ; i < $scope.selectedDocuments.length; i++) {
        if($scope.selectedDocuments[i].id == id){
          match = true;
        } 

      }

      return match;
  };
  $scope.sync = function(bool, item){

    if(bool){
      // add item
      $scope.selectedDocuments.push(item);
    } else {
      // remove item
      for(var i=0 ; i < $scope.selectedDocuments.length; i++) {
        if($scope.selectedDocuments[i].id == item.id){
          $scope.selectedDocuments.splice(i,1);
        }
      }      
    }
  };

  camForm.on('submit', function() {
      camForm.variableManager.createVariable({
        name: 'selectedDocuments',
        type: 'json',
        value:$scope.selectedDocuments
      });
    });

function toJsonValue(arr) {
var myJSON = "";
var FinalResult = JSON.stringify(arr);
myJSON = JSON.stringify({FinalResult});
var json=$scope.json={};
json=JSON.parse(myJSON);
return json;
}

 $scope.toggle = function (index){
    if($scope.jsonData[index].hidethis == undefined){
        $scope.jsonData[index].hidethis = true;
    }else{
        $scope.jsonData[index].hidethis = !$scope.jsonData[index].hidethis;
    }       
    }
</script>
<h2>My job List</h2>                                                                                                                                                                                     
    <div class="container">
        <table name ="table" class="table table-hover" style="width:100%;" cellspacing="0">
            <thead>
                <tr>
                    <th style="width:80px; height:25px;"><input style="width:25px; height:25px;" type="checkbox" onclick="checkAll(this)"></th>
                    <th style="width:140px;">id</th>
                    <th style="width:305px;">organizationNameEN</th>
                    <th style="width:305px;">organizationNameGE</th>
                     <th>&nbsp;</th>

                </tr>           
            </thead>
            <tbody ng-repeat="item in jsonData" >
                <tr>
                    <td><input type="checkbox" ng-change="sync(bool, item)" ng-model="bool" ng-checked="isChecked(item.id)"  ></td> 
                    <td><input style="width:305px;" type="number" id="id"  ng-model="item.id" readonly /></td>
                    <td><input style="width:305px;" type="text" id="organizationNameEN"  ng-model="item.organizationNameEN"  required /></td>
                     <td><input style="width:305px;" type="text" id="organizationNameGE"  ng-model="item.organizationNameGE"  required/></td>                     
                     <td><button class="btn btn-default btn-xs" ng-click="toggle($index)"><span class="glyphicon glyphicon-eye-open"></span></button></td>


    </tr>   
    <tr id="{{hideid + $index}}" ng-show="item.hidethis">
            <td>
    <label for="startDate" class="control-label">startDate</label>
     <div class="controls">
      <input style="width:105px;" id="strtDate" class="form-control" type="text" ng-model="item.startDate" required  readonly/>
      </div>
      <br>
      <label for="endDate" class="control-label">endDate</label>
       <div class="controls">
      <input style="width:105px;" id="endDate" class="form-control" type="text" ng-model="item.endDate" required  readonly/>
      </div>
    </td>
        </tr>               
   </tbody>
  </table>
    </div>

    <script>
function checkAll(bx) {
      var cbs = document.getElementsByTagName('input');
      for(var i=0; i < cbs.length; i++) {
        if(cbs[i].type == 'checkbox') {
          cbs[i].checked = bx.checked;
        }
      }
    }

</script>
</form>
4

1 回答 1

1

我做类似的事情。在我的第一个表单中,用户捕获了一些交易。表格 2 他们双重捕获(新交易必须与第一次捕获相匹配),表格 3 他们查看成功的交易并对其进行授权。

我通过以第一种形式创建一个 JSON 事务数组来处理这个问题。我使用如下代码将其保存到 on-submit 事件中的流程变量:

camForm.on('submit', function() {
  // this callback is executed when the form is submitted, *before* the submit request to
  // the server is executed

  // creating a new variable will add it to the form submit
  variableManager.createVariable({
    name: 'customVariable',
    type: 'String',
    value: 'Some Value...',
    isDirty: true
  });

我在后续表单中检索它,就像您在表单加载/变量获取事件中所做的那样。

如果 JSON 数组数据在后续表单中更新,我将使用如下代码将其保存回同一变量:

camForm.on('submit', function(evt) {
  var fieldValue = customField.val();
  var backendValue = variableManager.variable('customVariable').value;

  if(fieldValue === backendValue) {
    // prevent submit if value of form field was not changed
    evt.submitPrevented = true;

  } else {
    // set value in variable manager so that it can be sent to backend
    variableManager.variableValue('customVariable', fieldValue);
  }
});

这些代码片段来自Camunda 文档

于 2018-02-23T17:28:29.540 回答