2017-06-13 58 views

回答

0

這聽起來像你正在尋找的東西是這樣的:

function handleEvent(event, snapshot, optionalPreviousChildKey) { 
    switch (event) { 
    case "child_added": ... 
     break; 
    ... 
    } 
} 
ref.on("child_added", function(snapshot, previousChildKey) { handleEvent("child_added", snapshot, previousChildKey); }) 
ref.on("child_changed", function(snapshot, previousChildKey) { handleEvent("child_changed", snapshot); }) 
ref.on("child_moved", function(snapshot, previousChildKey) { handleEvent("child_moved", snapshot, previousChildKey); }) 
ref.on("child_removed", function(snapshot) { handleEvent("child_removed", snapshot); })