1 minute reading time (258 words)

How I write my Java Script code..

This is a sample of what I am doing this morning. I am evolving an idea that would use a different technology in the real world but its a very useful tool to showcase connecting to a firebase db from an Angular Java Script app. This is part of the Controller for a text field and this function happens when you interact with the text field. So typing into the box makes this function run every time.

$scope.changeField = function(str){

//string changes length each time this function runs and it can get smaller !
var newStringLength = str.length;


//console.log('str: '+ str);
//need to query the db and find matching entries..
//lets just try to return everything now..
if(str){

$scope.countries.once('value',function(placeSnapshot){
//console.log(placeSnapshot.val());
var aNames=[];
var aMatches=[];
placeSnapshot.forEach(function(leSnapshot) {

var name = leSnapshot.child('name/').val(); //eg Lisbon then L.A. then New York (for each place already in the firebase)

if(str.indexOf(name.charAt(0))!= -1)
{
//we need to loop through subsequent characters...
aMatches.push(name);
console.log(aMatches);
alert(str+' match '+name);
// need to add the match to a bind that is a repeater list..
}

//performance suggestion start matching after 3-4 characters..
//try matching using regex on say first 3 characters then next 3 etc... so (matches regex1 && matches regex2) then..

Lison : length is 5 so say user types in Lincoln what do we need to do ?

user types L - we check first character for 'L' against EVERY returned place ! very heavy.
Get a match so we store this match in an array of possible
user types i - "
user types n -

Set up CORS Headers for Static Content Pages Using...
Social Media Account Graphics And Posting Advice
 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Guest
Wednesday, 04 December 2024

Captcha Image

By accepting you will be accessing a service provided by a third-party external to https://cambs.eu/