领域-值不能转换为数字 [英] Realm - Value not convertible to a number
问题描述
Hello社区:)我用firebase-> realm实现了许多良好的工作功能.现在,我尝试编辑结构,并且正在浏览最疯狂的错误消息.
Hello community :) I implemented lots of good working functionality with firebase -> realm. Now i tried to edit a structure and I am running through the wildest error messages.
确定什么是正确的:
- Firebase 发送数据
- 数据已已转换(例如,Firebase具有品牌"作为数组->转换为Realm Schema的字符串)
- firebase 更新 时出现错误
- 并非每个firebase内容都具有所有字段(例如,您可以从Realm Schema中看到某些字段是可选:true)
- Firebase sends the data
- Data is Converted (e.g. Firebase has "brands" as array -> is converted to a string for Realm Schema)
- The error appears when firebase updates
- Not every firebase content has all fields (e.g. Like you can see out of Realm Schema some fields are optional: true)
我可能会遇到问题的字段:
- 也许不可能说ReferentList是可选的(或者我实现错误):请参阅领域架构 const ReferentsList
我尝试过的事情
- 在realm.create(领域集)之前进行调试结果:每个数据都以正确的格式出现
- 检查所有输入值是否为int,string,...
希望有人可以在这里为我提供帮助,因为我完全陷于这个问题及其继续进行我的项目的必要性.我想知道:
Hopefully someone can help me here because i got completely stuck with this issue and its necesarry to continue for my project. I want to know:
- 解决方案,为什么或做什么
- 以更好的方式调试领域的可能性 提前感谢您的时间和帮助:)
- The solution why or what to do
- A posibility to debug realm in a better way Thank you in advance for your time and help :)
错误消息: 值不能转换为数字
Firebase数据结构
- 开始":"2017-05-15T15:50:00.000Z",
- 说明":"abc",
- "end":"2017-05-15T16:15:00.000Z",
- "id":6,
- 语言":[1],
- 位置":"L 1.02",
- 成员":20,
- 指称":[1,3],
- 注册":为真,
- 标题":沉默之声",
- 曲目":6,
- 类型":3,
- 品牌":[1,2,3]
- "begin" : "2017-05-15T15:50:00.000Z",
- "description" : "abc",
- "end" : "2017-05-15T16:15:00.000Z",
- "id" : 6,
- "language" : [ 1 ],
- "location" : "L 1.02",
- "member" : 20,
- "referent" : [ 1, 3 ],
- "register" : true,
- "title" : "Sound of Silence",
- "track" : 6,
- "type" : 3,
- "brands" : [ 1, 2, 3 ]
领域架构
const ReferentListSchema = {
name: 'ReferentList',
properties: {
id: {
type: 'int',
optional: true
}
}
}
const LanguageListSchema = {
name: 'LanguageList',
properties: {
id: 'int'
}
}
const EventSchema = {
name: 'Events',
primaryKey: 'id',
properties: {
id: 'int',
begin: {
type: 'date',
optional: true
},
end: {
type: 'date',
optional: true
},
title: 'string',
description: 'string',
register: 'bool',
member: {
type: 'int',
optional: true
},
language: {
type: 'list',
objectType: 'LanguageList'
},
location: 'string',
referent: {
type: 'list',
objectType: 'ReferentList'
},
type: 'int',
track: {
type: 'int',
optional: true
},
img: {
type: 'string',
optional: true
},
brands:{
type: 'string',
optional: true
}
}
}
领域设置
set(obj) {
realm.write(() => {
if(obj.referent){
obj.referent = obj.referent.map(function(id) {
return {id};
})
}
if (obj.language){
obj.language = obj.language.map(function(id) {
return {id};
})
}
realm.create('Events', obj, true);
});
}
推荐答案
已解决:! 该问题已通过Firebase上的错误数据得到解决.某些日期对象已正确设置.
Solved:! The issue got solved through wrong data at firebase. Some Date Objects hasent been set correct.
我如何找到解决方案 当我尝试调试代码时,我在周围做了一个try/catch块:
How i got to the solution When i tried to debugg the code i made a try/catch block around:
try{
realm.create('Events', obj, true);
}catch(error){
console.log(obj);
console.log(error);
}
通过该调试,我发现正确的数据是错误的.在显示所有对象之前,然后显示错误.
Through this debug i found the right data wich was wrong. Before it just showed me all objects and afterwards the error.
由于有机会帮助遇到同样问题的人,我不会关闭这个问题.-
I wont close this question because of the chance to help someone with the same issues.-
这篇关于领域-值不能转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!