简体   繁体   English

如何序列化对象数组以形成角形字段

[英]How to serialize an array of objects to form fields in angular

I want to seriliaze json like this in my form fields: 我想在表单字段中像这样对json进行序列化:

 {FinalResult: [{"id":1,"organizationNameGE":"პსდა2","organizatio…":"02-16-2018","$$hashKey":"0Q0","priority":"1"}]"}

and for this reason i use this code: 因此,我使用以下代码:

<script cam-script type="text/form-script">

    camForm.on('form-loaded', function() {
      // tell the form SDK to fetch the variable named 'document'
      camForm.variableManager.fetchVariable('selectedDocuments');
    });
    camForm.on('variables-fetched', function() {
      // work with the variable (bind it to the current AngularJS $scope)
      $scope.selectedDocuments =ConvertToJsonArray(camForm.variableManager.variableValue('selectedDocuments'));

    });
function ConvertToJsonArray(arr){
var jsonArray=arr.FinalResult;
return jsonArray;
}
  </script>
<div class="container" ng-repeat="item in selectedDocuments track by $index">
<div class="control-group"  >
    <label for="id" class="control-label">საიდენტიფიკაციო კოდი</label>
     <div class="controls">
      <input id="id" class="form-control" type="number" ng-model="item.id" required  readonly/>
    </div>
  </div>
    <div class="control-group" >
    <label for="cardNumber" class="control-label">ბარათის ნომერი</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">კომპანიის სახელი ქართულად</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">კომპანიის სახელი ლათინურად</label>
   <div class="controls">
      <input id="organizationNameEN" class="form-control" type="text" ng-model="item.organizationNameEN" required />
    </div>
  </div>    
   <div class="control-group" >
    <label for="Approved" class="control-label">Approved</label>  
   <input type="checkbox"
       class="form-control" 
       cam-variable-name="Approved"
       cam-variable-type="Boolean"/> 
       </div>       
      <div class="form-group">
      <label for="refusalComment" class="control-label">კომენტარი უარზე</label>
      <input type="text"
           class="form-control" 
           cam-variable-type="String"
           cam-variable-name="refusalComment"
           name="კკომენტარი უარზედ"/>
            </div> 
            </div> 

But this doesn't doesn't seem to be enough, what should i change to display this json data into my form? 但这似乎还不够,我应该怎么做才能将此json数据显示到表单中? should i use ng-for instead of ng-repeat? 我应该使用ng-for而不是ng-repeat吗?

(ps there is no any internal errors in console) (ps控制台中没有任何内部错误)

It looks you are taking data in the array FinalResult. 看起来您正在从数组FinalResult中获取数据。 Iam not sure why you used selectedDocuments . 我不确定为什么要使用selectedDocuments。

<div class="container" ng-repeat="item in selectedDocuments track by $index">

Use this isntead of selectedDocuments 使用selectedDocument的此注释

<div class="container" ng-repeat="item in FinalResult track by $index">

Please let me know if it helps. 请告诉我是否有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM