In the sever side i have an array with structure like that:
array ('_1489378560544_544' => array (
'customer_group_id' => '0',
'permission_id' => 'disable_products_price',),
'_1489740032764_764' => array (
'customer_group_id' => '',
'permission_id' => '',),)
So now in the client side i want to create an javascript array with the same structure to server side. Is there any possible way to do that?
So after i got all data separately how can i organize my array look like this
var arr = [{_1489378560544_544 : [customer_group_id : 0 , permission_id : 'permission_id'] }]
Here is my javascript get data function:
$('#category_permission > tbody > tr').each(function() {
var id = $(this).attr("id");
var customer_group_id = $(this).children('td:first').children('select:first').val();
var permission_id = $(this).children('td:nth-child(2)').children('select:first').val();
});
Thanks for your help.
Something like this :var arr = [{_1489378560544_544 : [customer_group_id : 0 , permission_id : 'permission_id'] }]
You can use json_encode
to convert your PHP array to a JSON string and use JSON.parse()
to obtain the equivalent Javascript object. Take a look here: https://www.w3schools.com/js/js_json.asp
in your php view file
jsStr = '<?php echo json_encode($array)?>'
jsObj = JSON.parse(jsStr);
console.log(jsObj.keyname);
like that all keys can be accessed to get the value. javascript don't support alphanumerical keys for array. Answer from @Mistalis should help.