Javascript // searching JSON objects quick // accessing JSON elements

OBJECT:

'use strict';

var slotIndexes = [
    { 
	'slot' : 'live',
	'index': 0
    },
    { 
	'slot' : 'achtziger',
	'index': 1
    },
    { 
	'slot' : 'neunziger',
	'index': 2
    },
    { 
	'slot' : 'relax',
	'index': 3
    },
    { 
	'slot' : 'rock',
	'index': 4
    },
    { 
	'slot' : 'brandneu',
	'index': 5
    },
    { 
	'slot' : 'black and dance',
	'index': 6
    },
    { 
	'slot' : 'deutsche hits',
	'index': 7
    },
// RECOUNT INDEXES IN CASE OF ENABLING WEIHNACHTSHITS
//    { 
//	'slot' : 'weihnachtshits',
//	'index': 8
//    },
// RECOUNT INDEXES IN CASE OF ENABLING WEIHNACHTSHITS
    { 
	'slot' : 'berlin club',
	'index': 8
    },
    { 
	'slot' : 'fetenhits',
	'index': 9
    },
    { 
	'slot' : 'news',
	'index': 10
    },
    { 
	'slot' : 'nachrichten',
	'index': 10
    }
];

module.exports = slotIndexes;

SEARCHING:


var slotIndexes  = require('./slotIndexes');
function getIndexBySlot(slot) {
  return slotIndexes.filter(
      function(slotIndexes){ return slotIndexes.slot == slot }
  );
};

 ...
var indexFound = getIndexBySlot(channel);
 ...
if ("undefined" !== typeof indexFound[0]) {
  console.log('DEBUG -> ' + this.handler.state + ' Slot found!');
  this.attributes['index'] = indexFound[0].index;
  this.attributes['offsetInMilliseconds'] = 0;
}


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s