@@ -122,10 +122,10 @@ var db, birthdays, fbA, tm, temp;
122122 _birthdays = _db . getCollection ( 'birthdays' ) ;
123123 if ( ! _birthdays ) {
124124 _birthdays = _db . addCollection ( 'birthdays' , {
125- indices : [ 'fbKey ' ] ,
125+ indices : [ '$id ' ] ,
126126 clone : true
127127 } ) ;
128- _birthdays . ensureUniqueIndex ( 'fbKey ' ) ;
128+ _birthdays . ensureUniqueIndex ( '$id ' ) ;
129129 }
130130
131131 var isEnabled = true ;
@@ -140,13 +140,13 @@ var db, birthdays, fbA, tm, temp;
140140
141141 if ( ! _temp ) {
142142 _temp = _db . addCollection ( 'temp' , {
143- indices : [ 'fbKey ' ] ,
143+ indices : [ '$id ' ] ,
144144 clone : true
145145 } ) ;
146- _temp . ensureUniqueIndex ( 'fbKey ' ) ;
146+ _temp . ensureUniqueIndex ( '$id ' ) ;
147147
148148 //ejemplo de como obtener el registro
149- // temp.by('fbKey ',"-K5fLRn_P7GM1VceDQTa")
149+ // temp.by('$id ',"-K5fLRn_P7GM1VceDQTa")
150150 }
151151
152152 temp = _temp ;
@@ -156,13 +156,24 @@ var db, birthdays, fbA, tm, temp;
156156 function trySync ( ) {
157157 _temp . data . forEach ( function ( obj , i ) {
158158 console . log ( obj , i ) ;
159- _bdRef . child ( obj . fbKey ) . set ( obj . fbVal , syncCb ( obj . fbKey ) ) ;
159+ var fbKey = obj . $id ;
160+ var objClone = angular . copy ( obj ) ;
161+
162+
163+
164+ if ( delete objClone . $id && delete objClone . $loki ) {
165+ console . log ( 'format obj' , fbKey , objClone )
166+ _bdRef . child ( fbKey ) . set ( objClone , syncCb ( fbKey ) ) ;
167+
168+ }
169+
160170 } ) ;
161171 }
162172
163173 function syncCb ( fbKey ) {
164174
165175 function cbFb ( error ) {
176+
166177 if ( error ) {
167178 console . error ( 'error' ) ;
168179 } else {
@@ -232,12 +243,12 @@ var db, birthdays, fbA, tm, temp;
232243
233244 if ( ! _temp ) {
234245 _temp = _db . addCollection ( 'temp' , {
235- indices : [ 'fbKey ' ]
246+ indices : [ '$id ' ]
236247 } ) ;
237- _temp . ensureUniqueIndex ( 'fbKey ' ) ;
248+ _temp . ensureUniqueIndex ( '$id ' ) ;
238249
239250 //ejemplo de como obtener el registro
240- // temp.by('fbKey ',"-K5fLRn_P7GM1VceDQTa")
251+ // temp.by('$id ',"-K5fLRn_P7GM1VceDQTa")
241252 }
242253 var isEnabled = true ;
243254 _birthdays . setChangesApi ( isEnabled ) ;
@@ -286,14 +297,17 @@ var db, birthdays, fbA, tm, temp;
286297 var key = _bd . $keyAt ( lastIndex ) ;
287298
288299 birthday . $id = key ;
289- // var birthday = _bd.$getRecord(key);
290- var newObj = {
291- fbKey : key ,
292- fbVal : birthday
293- } ;
294- console . log ( lastIndex , _bd [ lastIndex ] , key , newObj ) ;
295- _birthdays . insert ( newObj ) ;
296- _temp . insert ( newObj ) ;
300+ /* // var birthday = _bd.$getRecord(key);
301+ var newObj = {
302+ fbKey: key,
303+ fbVal: birthday
304+ };
305+ console.log(lastIndex, _bd[lastIndex], key, newObj);
306+ _birthdays.insert(newObj);
307+ _temp.insert(newObj);*/
308+
309+ _birthdays . insert ( birthday ) ;
310+ _temp . insert ( birthday ) ;
297311 }
298312
299313 function oK ( ref ) {
@@ -320,7 +334,7 @@ var db, birthdays, fbA, tm, temp;
320334
321335 function removeTempbyId ( fbKey ) {
322336 _temp . removeWhere ( {
323- 'fbKey ' : fbKey
337+ '$id ' : fbKey
324338 } ) ;
325339 }
326340
@@ -332,7 +346,7 @@ var db, birthdays, fbA, tm, temp;
332346 function getTempById ( key ) {
333347
334348 // $timeout(function() {
335- var obj = temp . by ( 'fbKey ' , key ) ;
349+ var obj = temp . by ( '$id ' , key ) ;
336350 // console.log('obj', obj);
337351 return obj ;
338352 // }, 200);
0 commit comments