관리 메뉴

이사작전.com IT Blog

How to use the firebase like search 본문

Framework/Google Firebase

How to use the firebase like search

말랑고양 플랫폼공작소 2019. 12. 1. 16:51

Hi there!


I will let you know something!


It is How to use the firebase like search.


I've been thinking a lot about this problem.


As we know, the FireBase doesn't have [like search] capability.


Then.. let's use jquery. Like me.


reference : https://stackoverflow.com/questions/3728022/jquery-string-contains-check


It's work for me.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
        function startDatabaseQueries(searchString) {
 
            var listeningFirebaseRefs = [];
            var recentPostsRef = firebase.database().ref('yourPath').orderByChild('yourKey').limitToLast(30);
            var fetchPosts = function(postsRef) {
                postsRef.on('child_added'function(data) {
                    var name = data.val().name;
                    if(name.indexOf(searchString) != -1){
                        console.log("found!");
                    }else{
                        console.log("no data!");
                    }
                });
            };
 
            // Fetching and displaying all posts of each sections.
            fetchPosts(recentPostsRef);
 
            // Keep track of all Firebase refs we are listening to.
            listeningFirebaseRefs.push(recentPostsRef);
 
        }
cs


good luck bro!


#firebase #like #search

0 Comments
댓글쓰기 폼