2015-11-25 33 views
-1

Firebase - 如何使用「on」觀看要更改的對象列表?Firebase - 如何使用「on」觀看要更改的對象列表?

我有一個配置文件列表,並希望觀察此列表來檢查是否添加新的對象或配置文件更新。所以對列表的任何改變。

當前代碼嘗試:

var ref = new Firebase("https://markng2.firebaseio.com");   
var refProfiles = ref.child('profiles'); 

refProfiles.on('value', function(dataSnapshot) { 
     //Change has occurred in the list of profiles. 
}); 

我的火力分貝見圖片:

enter image description here

+0

我已經更新上面顯示我的代碼。 @CodeiSir – AngularM

回答

1

如果你想知道,如果加入的輪廓或特定的配置文件被改變,你最好聽聽Firebase的child_活動:

var ref = new Firebase("https://markng2.firebaseio.com");   
    var refProfiles = ref.child('profiles'); 

    refProfiles.on('child_added', function(dataSnapshot) { 
     var profile = dataSnapshot.val(); 
     console.log('Profile added: ', profile); 
    }); 

    refProfiles.on('child_changed', function(dataSnapshot) { 
     var profile = dataSnapshot.val(); 
     console.log('Profile changed: ', profile); 
    }); 

查看更多信息Firebase documentation on reading data