[英]Filtered REALM with React Native
I want to search for certain data in a range of one year, and I am not taking this range and I put directly the variable yearLive
of the Predicate error.我想在一年的范围内搜索某些数据,我没有取这个范围,我直接把谓词错误的变量
yearLive
。
but all members of each family are returning and not just one year old children.但每个家庭的所有成员都回来了,而不仅仅是一岁的孩子。
obterCriancaUmAno = familia_uuid => {
const now = moment().format('YYYY-MM-DDT00:00:00');
const oneYearAgo = moment()
.subtract(1, 'year')
.format('YYYY-MM-DDT00:00:00');
let yearLive = ` AND BEGINSWITH birth_date = ${oneYearAgo} AND ENDSWITH birth_date = ${now}`;
return new Promise(async (resolve, reject) => {
const realm = await getRealm();
try {
let families = Array.from(
realm
.objects('Family')
.filtered(
`familia_uuid = "${family_uuid}" AND ativo = true AND saida_cadastro = null`,
yearLive,
),
);
resolve(families);
} catch (error) {
reject(error);
}
});
};
this was the solution I found for my problem这是我为我的问题找到的解决方案
obterTodosMembrosFamiliaUmAno = () => {
const now = moment().format('YYYY-MM-DD');
const oneYearAgo = moment()
.subtract(1, 'year')
.format('YYYY-MM-DD');
return new Promise(async (resolve, reject) => {
const realm = await getRealm();
try {
let Membros = realm
.objects('MembroFamilia')
.filtered(`ativo = true AND saida_cadastro = null `);
//filter childrens
let listMembros = await Membros.filter(function(a) {
return a.data_nascimento >= oneYearAgo && a.data_nascimento < now;
});
resolve(listMembros);
} catch (error) {
reject(error);
}
});
}; };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.