2016-04-26 42 views
2

我要插入我的数据在火力,像这样:Angular-firebase。数据未正确插入

cities:{ 
    Tokyo:{ 
     name: "Tokyo, JP" 
    } 
    London:{ 
     name: "London, UK" 
    } 

    and so on... 

我手动一些数据插入从网上GUI:cities

但不幸的是它被插入这样:minsk

我的代码

的火力地堡工厂:

export default function CitiesFactory($firebaseArray, Firebase) { 
    'ngInject'; 
    var ref = new Firebase("https://name.firebaseio.com/"); 
    return $firebaseArray(ref.child('cities')); 
} 

控制器(添加功能):

$scope.addoras = function(city) { 
     CitiesFactory.$add({ 
      city: { 
       name: city 
      } 
     }).then(function(CitiesFactory) { 
      var id = CitiesFactory.key(); 
      console.log('Added Contact ' + id); 
      $scope.addorasmodel = ''; 

     }); 
    }; 

有人能帮助我吗?

+0

另见http://stackoverflow.com/questions/36845390/firebase-help-avoid -new-id-on-new-push/36846118#36846118 –

回答

2

当您使用$ add()时,它将生成一个唯一的推送ID,如documentation中所述。

如果你想避免你可以使用这些设置唯一ID的()或update()(Documentation

var ref = new Firebase("https://name.firebaseio.com/"); 
ref.set({ 
    city: { 
     name: city 
    } 
}); 

var ref = new Firebase("https://name.firebaseio.com/"); 
ref.update({ 
    city: { 
     name: city 
    } 
}); 
+0

谢谢..... ..... –