0

我想添加我的 selectedDocuments 对象'comment'项目及其值(这样我想以呈现此 selectedDocuments 对象值的形式显示此输入,并且在提交此输入后我希望将其添加到 selectedDocuments 对象)我有在这里尝试了几种变体是我的代码:

var variableManager = camForm.variableManager;
$scope.refusalComment=null;

camForm.on('form-loaded', function() {
    // tell the form SDK to fetch the variable named 'document'
    variableManager.fetchVariable('selectedDocuments');
});

camForm.on('variables-fetched', function() {
   // work with the variable (bind it to the current AngularJS $scope)
   $scope.refusalComment = variableManager.variable('refusalComment').value;

   console.log( $scope.refusalComment+"=========refusalComment==========");

   $scope.selectedDocuments =ConvertToJsonArray(variableManager.variable('selectedDocuments').value);    
});

function ConvertToJsonArray(arr){
    //I  have  replaced FinalResult with data
    var  jsonArray=[];
    var json=$scope.json={};
    var json1=$scope.json1={};
    var json2=$scope.json2={};
    json=JSON.parse(arr);
    json1=json.FinalResult;
    json2=JSON.parse(json1);

    //console.log(json1);
    return json2;
}

function EnrichValue(data,comment){
    var json=$scope.json={};
    var json1=$scope.json1={};
    json=JSON.parse(data);
    json1=json.FinalResult;
    json1=JSON.parse(json1);

    for(var i=0;i<Object.keys(json1).length;i++){
       json1[i].comment=comment;
    }

    console.log(json1);
    return json1;
}

这是我的html代码:

<div class="control-group"  >
            <label for="id" class="control-label">code</label>
             <div class="controls">
              <input id="id" class="form-control" type="text" ng-model="item.id"  required  readonly/>
            </div>
          </div>
            <div class="control-group" >
            <label for="cardNumber" class="control-label">number </label>
            <div class="controls">
              <input id="cardNumber" class="form-control" type="text" ng-model="item.cardNumber" required />
            </div>
          </div>
           <div class="control-group"  >
            <label for="organizationNameGE" class="control-label" >name</label>
            <div class="controls">
              <input id="organizationNameGE" class="form-control" type="text" ng-model="item.organizationNameGE"  required />
            </div>
          </div>
              <div class="control-group"  >
            <label for="organizationNameEN" class="control-label">write  comment </label>
           <div class="controls">
              <input id="comment" class="form-control" type="text" cam-variable-name="comment" cam-variable-type="String" value="write  comment" />
            </div>
          </div>  

          </div>   

                <div class="container">
                <div class="control-group" >
                <label for="approved" class="control-label">approve</label>  
                <input type="checkbox" id="approved"
               class="form-control" 
               cam-variable-name="approved"
               cam-variable-type="Boolean"/> 
               </div>  
                </div>  

        </form>

当我运行这段代码时,我总是得到这个错误无法获得未定义的值(我的意思是评论)我应该如何让这段代码工作?

4

1 回答 1

0

好吧,我在您的代码中看不到您实例化变量注释的任何点。我建议添加:

var comment = ''; 

到你的 JS 代码。

于 2018-04-03T20:31:01.877 回答