我正在React Native中实现Realm。上下文是我在顶部声明了2个架构,即“ PortfolioData”,其架构类型为“ PriceAChangeSchema”。
现在,在更新屏幕上,我只需要更新PriceAChangeSchema中的3个值,即balance,lastPrice和totalVal。当我尝试仅将3个值推入领域写入功能时,它成功地覆盖了3个值,但是PriceAChange模式的其余值变为空,这是我不希望的。
P.S推送后,PortfolioData的值保持不变,但PriceAChange模式值变为空。 ?
class PriceAChangeSchema extends Realm.Object { }
PriceAChangeSchema.schema = {
name: 'PriceAChange',
properties: {
icon: 'string?',
cryptoName: 'string?',
balance: 'string?',
lastPrice: 'string?',
change: 'string?',
totalVal: 'string?',
}
};
class PortfolioDataSchema extends Realm.Object { }
PortfolioDataSchema.schema = {
name: 'PortfolioData',
primaryKey: 'select',
properties: {
from: 'string?',
select: 'string',
apikey: 'string?',
secretkey: 'string?',
address: 'string?',
logoLink: 'string?',
priceandchange: 'PriceAChange[]'
}
}
realm.write(() => {
const ExchangeIns = realm.create('PortfolioData', {
select: select, //primary key
priceandchange: [], //want to change specifics
}, true);
ExchangeIns.priceandchange.push({
balance: '0.004',
lastPrice: '2.22',
totalVal: '3.5',
});
});