【发布时间】:2016-02-26 08:11:57
【问题描述】:
我在 /items 中有 Firebase 条目,属性为 title 和 points。我正在尝试在输入新项目之前检查是否存在相同的 title 项目。
这是我所拥有的,但它没有发生:
app.controller('ItemController', function($scope, FURL, $firebase, $location, toaster) {
var ref = new Firebase(FURL);
var fbItems = $firebase(ref.child('items')).$asArray();
$scope.addItem = function(item) {
// var iItem = $scope.item.title;
var userId = $scope.item.title;
checkIfUserExists(userId);
};
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
} else {
alert('user ' + userId + ' does not exist!');
}
}
function checkIfUserExists(userId) {
ref.child('items').once('value', function(snapshot) {
var exists = (snapshot.val() !== null);
userExistsCallback(userId, exists);
});
}
});
【问题讨论】:
标签: javascript angularjs firebase angularfire firebase-security