javascript - Get and store multidimensional array not JSON in Firebase -


i using multidimensional array (not json) in javascript.

var ar = [  ['1','2013','a','name1','1','1','3','3','1','2','3','4',''],  ['2','2014','b','name2','1','2','3','1','1','2','3','5',''],  ['3','2015','c','name3','1','2','4','4','1','2','5','4',''] ]; 

to send or store array ar firebase cloud use:

var data = new firebase("xxxx.firebaseio.com"); data.set(ar); 

i use 2d array form lot.

what option have or store individual data or array firebase cloud?

  1. like refresh , sync array ar cloud
  2. store new data cloud ar[2][3] = "new text"
  3. get value cloud var x = ar[2][3]

hope can help

thanks k

var array = [  ['1','2013','a','name1','1','1','3','3','1','2','3','4',''],  ['2','2014','b','name2','1','2','3','1','1','2','3','5',''],  ['3','2015','c','name3','1','2','4','4','1','2','5','4',''] ];  var ref = new firebase('https://xxxx.firebaseio.com/');  ref.set(array);  ref.on('value', function(snapshot) {   var value = snapshot.val();    console.log(value);     console.log(value[2][3]); }); 

the output above is:

[["1", "2013", "a", "name1", "1", "1", "3", "3", "1", "2", "3", "4", ""],   ["2", "2014", "b", "name2", "1", "2", "3", "1", "1", "2", "3", "5", ""],   ["3", "2015", "c", "name3", "1", "2", "4", "4", "1", "2", "5", "4", ""]] "name3" 

any time part of array changes, value event fire again , on('value' callback invoked.

if want update array, have 2 options.

array[2][3] = "new text"; ref.set(array); 

this send entire array firebase. alternative update 1 element @ [2][3] straight in database:

ref.child(2).child(3).set("newest text"); 

no matter of 2 approaches use, on('value' callback invoked again.

check out jsbin working version of code: http://jsbin.com/nawatetuya/edit?js,console


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -