Get the index ID of an item in Firebase AngularFire

后端 未结 3 877
粉色の甜心
粉色の甜心 2021-02-06 17:25

A similar question was asked here, but the one accepted answer doesn\'t really answer the question.

Using AngularFire, is it possible to to create relational-style datab

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-06 17:38

    I have the best and quickest answer for all such kind of problems guys!!!

    var chru;
        var ref = new Firebase("https://myapp.firebaseio.com/users/");
        var sync = $firebase(ref);
        var users= syncSelect.$asArray();
        $scope.users= users;
        users.$loaded().then(function() {
            chru = users.length;
        });
    
        $scope.specificIdOnSelect = function() {
            var jj;
            for (jj = 0; jj < chru; jj++) {
                var keyer = users.$keyAt(jj);
                var rec = users.$getRecord(keyer);
    
                if ($scope.userSelected== rec.name) {
                    alert("Unique Key of " + $scope.users+ " is " + users.$keyAt(jj));
                }
            }
        };
    
        $scope.allIds = function() {
            var jj;
            for (jj = 0; jj < chru; jj++) {
                var keyer = users.$keyAt(jj);
                var rec = users.$getRecord(keyer);
                alert("Unique Key of " + $scope.users+ " is " + users.$keyAt(jj));
            }
        };
    

    Try it and then please let me know if this helps!!!

提交回复
热议问题