繁体   English   中英

特定领域数据库值必须更新

[英]Specific Realm database values must update

我正在React Native中实现Realm。 上下文是我在顶部声明了2个模式,即“ PortfolioData”,其类型为“ PriceAChangeSchema”。

现在,在更新屏幕上,我只需要更新PriceAChangeSchema中的3个值,即balance,lastPrice和totalVal。 当我尝试仅将3个值压入领域写入函数时,它成功地覆盖了3个值,但是PriceAChange模式的其余值变为空,我不想这样做。

PS推送时的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',
            });
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM