我有一个Invoice数组,其中包含Products数组中的对象,并且我尝试独立地更新每个Invoice数组对象,但是当我更新一个对象的属性时,所有其他对象的属性都会更改。
例如,在我的第一张发票中,我向列表中添加了2笔,然后在第二张发票中,我添加了一支笔,但是在添加了第二张发票后,第一张发票的count属性也更改为1。 >
如何更新其中一个而不影响另一个?
// First Invoice
[
{"date":0,"id":1,"products":
[
{"count":"2","format":"","id":"6921738073439","name":"pen","price":"15"}
]
}
]
// Second Invoice
[
{"date":0,"id":1,"products":
[
{"count":"1","format":"","id":"6921738073439","name":"pen","price":"15"}
]
},
{"date":0,"id":1,"products":
[
{"count":"1","format":"","id":"6921738073439","name":"pen","price":"15"}
]
}
]
更新:我还包括了我如何创建发票的Java代码:
public void save(final Invoice object) {
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
realm.copyToRealmOrUpdate((Invoice) object);
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
Log.i("***", "success");
}
}, new Realm.Transaction.OnError() {
@Override
public void onError(Throwable error) {
Log.i("***", error.toString());
}
});
}