【问题标题】:AngularJS - Binding list of objectsAngularJS - 对象的绑定列表
【发布时间】:2016-01-30 20:24:18
【问题描述】:

我对在 AngularJS 应用程序中进行对象映射感到震惊。

在 html 中,我有大约 10 行,每行有一个标签和 2 个日期字段。

每一行都映射到一个java对象,如下所示

    public class RowObject {

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


    // getters / setters    

}

我正在尝试使用如下的 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>              

错误信息

    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"])    

【问题讨论】:

  • 如果我的回答通过接受/评论解决了您的问题,请告诉我:)
  • @IggY 我正在尝试做同样的事情,但它不起作用。使用angularjs在html上显示java对象

标签: javascript java angularjs rest


【解决方案1】:

我认为您的问题出在 Java 方面。我不能告诉你确切的位置,因为你没有提供你的 java 代码,但一般的问题是你试图反序列化一个 json 对象:{} 到一个 ArrayList(期望一个 json 数组:[])

只是对您的角度代码的评论,我建议您使用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>   

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 2017-05-15
    相关资源
    最近更新 更多