简体   繁体   English

AngularJS-绑定对象列表

[英]AngularJS - Binding list of objects

I am struck in doing the object mapping in AngularJS application. 我对在AngularJS应用程序中执行对象映射感到震惊。

In html I have around 10 rows, each row with a label and 2 date fields. 在html中,我大约有10行,每行有一个标签和2个日期字段。

Each row is mapped to a java object as below 每行都映射到一个Java对象,如下所示

    public class RowObject {

    private Long id;
    private String label;
    private Date startDate;
    private Date endDate;


    // getters / setters    

}

I am trying with a html code as below 我正在尝试使用如下的html代码

    <div class="form-group">
        <label class="control-label col-md-3">Row 1</label>
        <div class="input-group col-md-4">
            <input id="startDate1" type="text" class="form-control" ng-model="entity.rowObjects[0].startDate">
            <input id="endDate1" type="text" class="form-control" ng-model="entity.rowObjects[0].endDate">
            <input type="text" ng-model="entity.rowObjects[0].id" ng-value="1" style="display: none;">
        </div>
    </div>      

    <div class="form-group">
        <label class="control-label col-md-3">Row 2</label>
        <div class="input-group col-md-4">
            <input id="startDate2" type="text" class="form-control" ng-model="entity.rowObjects[1].startDate">
            <input id="endDate2" type="text" class="form-control" ng-model="entity.rowObjects[1].endDate">
            <input type="text" ng-model="entity.rowObjects[1].id" ng-value="1" style="display: none;">
        </div>
    </div>              

Error message 错误信息

    Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
 at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@40cc74d9; line: 1, column: 2] (through reference chain: com.jai.model.Entity["rowObjects"])    

I think your problem is on the Java side. 我认为您的问题出在Java方面。 I can't tell you exactly where as you didn't provided your java code, but the general problem is your trying to deserialize a json object : {} into an ArrayList (that expect a json array : [] ) 我无法确切地告诉您您未提供Java代码的位置,但是一般的问题是您试图将json对象: {}反序列化为ArrayList(需要json数组: []

Just a comment about your angular code, I advise you to use ng-repeat : 只是关于您的角度代码的注释,我建议您使用ng-repeat

<div class="form-group" ng-repeat="value in entity.rowObjects">
    <label class="control-label col-md-3">Row {{$index}}</label>
    <div class="input-group col-md-4">
        <input id="startDate1" type="text" class="form-control" ng-model="value.startDate">
        <input id="endDate1" type="text" class="form-control" ng-model="value.endDate">
        <input type="text" ng-model="value.id" ng-value="1" style="display: none;">
    </div>
</div>   

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

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