gpt4 book ai didi

javascript - AngularJS - 对象的绑定(bind)列表

转载 作者:行者123 更新时间:2023-11-30 07:49:55 25 4
gpt4 key购买 nike

我对在 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"])

最佳答案

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

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

关于javascript - AngularJS - 对象的绑定(bind)列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33435500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com