0
這些是我的境界對象。我有洞和圓。我試圖在一次寫入中填充18個孔對象,但在過去的幾個小時裏我一直困在這裏,我似乎無法理解我要出錯的地方。推送到領域列表
class Hole extends Realm.Object {}
Hole.schema = {
name: 'Hole',
primaryKey: 'id',
properties: {
id: 'int',
fullStroke: 'int',
halfStroke: 'int',
puts: 'int',
firstPutDistance: 'int',
penalties: 'int',
fairway: 'string'
},
};
class Round extends Realm.Object {}
Round.schema = {
name: 'Round',
primaryKey: 'id',
properties: {
id: 'string',
done: 'string',
holes: {type: 'list', objectType: 'Hole'}
},
};
這是我的函數,試圖將每個孔推入Round的孔屬性。任何幫助將不勝感激。
exportRound =() => {
let holesObjects = realm.objects('Hole')
if(holesObjects.length < 9){
alert('Enter stats for at least 9 holes please')
}
else{
var sortedHoles = holesObjects.sorted('id')
currentRound = realm.objects('Round').filtered('done == "no"')
for(var i = 1; i < holesObjects.length; i++){
console.log(holesObjects.filtered('id == i'))
realm.write(()=> currentRound.holes.push(holesObjects.filtered('id == {i}')))
}
}
}