$("#invoice_list").dragtable({
dataHeader: "data-name",
retriveOrder: function () {
console.log(JSON.parse(JSON.parse(localStorage.getItem('tableorder')))); // typeof === "string"
console.log(JSON.parse(localStorage.getItem('tableorder'))); typeof === "object"
return JSON.parse(JSON.parse(localStorage.getItem('tableorder')));
},
stop: function () {
var order = $(this).dragtable('order');
console.log(order); // typeof order === "object" zwykły array
localStorage.setItem('tableorder', JSON.stringify(order));
ColumnManager.sortColumns(order);
}
});
Z pozoru zwykły od taki sobie kod w js, a jednak nie.. W momencie wykonania localStorage.setItem('tableorder', JSON.stringify(order));
do localStorage trafia taki string:
"[\"invoice_id\", \"buyer\", \"iv_type\", \"sell_date\", \"bill_date\", \"due_date\", \"invoice_amount_net\", \"vat_value\", \"invnumber\", \"invoice_amount_gross\", \"payment_left\", \"payment_sum\", \"last_payment_date\", \"user\", \"department_name\", \"drs\", \"rate\", \"commission_percent\", \"is_address_tracking\", \"is_offer_exclusive\", \"is_krd\", \"dc_stage\", \"comment\", \"\"]"
Jeżeli chce znowu dostac tablicę swoich kolumn to musze zrobić dwa razy JSON.parse.
What the javascript?