我需要在Knockout JS中使用java.util.Map。 Map条目的key
始终是表单输入的路径/名称; value
是错误消息,应显示在表单输入旁边:
例如:MyObject.getErrors().push("myObjects[0].myField1"), "This field is mandatory!");
如何在Knockout JS中检查Map键是否等于输入名称,如果是,则在表单输入中附加“error <span>
”?
甚至有可能吗?
JavaObject:
public class MyObject {
public String myField1;
public String myField2;
private Map<String, String> errors = new HashMap<String, String>();
}
淘汰赛对象:
function MyObject(data) {
this.field1 = ko.observable(data.field1);
this.field1 = ko.observable(data.field1);
this.errors = [{
?
}]
}
JSON响应:
{
"class": "MyObjectHelper",
"myObjects": [
{
"class": "MyObject",
"errors": {
},
"field1": "ABC123",
"field2": "01.01"
},
{
"class": "com.itensis.leina16.application.data.domain.Configuration",
"errors": {
"myObjects[1].field2": "Is required"
},
"field1": "ASDF123",
"field2": ""
},
{
"class": "com.itensis.leina16.application.data.domain.Configuration",
"errors": {
"configurations[2].field1": "Is required",
"configurations[2].field2": "Is required"
},
"field1": "",
"field2": ""
}
],
"hasErrors": true
}