Eavis / web_app

0 stars 0 forks source link

Data Organization in js #30

Open Eavis opened 7 years ago

Eavis commented 7 years ago

The data I've got is an array of objects [Object1, Object2, Object3, ... ] Each Object is an json format {"key1":"value1","key2":"value2","key3":"value3","key4":"value4"...} To get all the value of a few given key

function getFields(input, field) {
  var output = [];
  for (var i=0; i < input.length ; ++i){
    output.push(input[i][field]);
  }
  return output;    //loop through all the objects and find all the values for one key
}
$('.destination .list-group-item').each(function(){
         chosen_field.push($(this).text());
       });
       var json_join = new Array();
       for (var i = 0; i < chosen_field.length; i++) {
           var result = (getFields(data,chosen_field[i]));
           var json = new Object();
           json.key = chosen_field[i];
           json.value = JSON.stringify(result);
           json_join.push(json);
        }
//loop through all the selected fields and return each value array and combine to a new json file 
preparing for sending to php in the format of json file.
Eavis commented 7 years ago

Sending JSON to PHP using ajax

https://stackoverflow.com/questions/10955017/sending-json-to-php-using-ajax

Eavis commented 7 years ago

PHP deal with forms

http://php.net/manual/zh/tutorial.forms.php