Answer the question
In order to leave comments, you need to log in
How to properly discard generated json?
I'm trying to create my extension. It turns out js script form json, and then throw in input type='hidden' Here is the form itself
<form id="formMenu" action="update" method="post">
<div class="form-group field-menuget-key_setup required">
<label class="control-label" for="menuget-key_setup">Введите название меню (на английском)</label>
<input id="menuget-key_setup" class="name" name="MenuGet[key_setup]" value="forHer" aria-required="true" type="text">
</div><div class="form-group field-contentForJson required">
<input id="contentForJson" class="form-control" name="MenuGet[vaelye]" value="" type="hidden">
</div>
<a id="secures" class="btn btn-success col-lg-offset-8 col-md-offset-8 col-sm-offset-6" href="#">Сохранить меню</a>
$("#secures").click(function (e) {
e.preventDefault();
var menu = {};
var extra = {};
$("#menu-to-edit li").each(function (i) {
if ($(this).data('menu')) {
var id = $(this).data('id');
var model = $(this).data('model');
var alias = $(this).data('alias');
var depth = parseInt($(this).attr('data-depth'));
var path = $(this).data('path');
title = $(this).data('title').toString();
var key = 'menu' + $(this).attr('data-item');
var addmenu = {
title: title,
id: id,
model: model,
alias: alias,
depth: depth,
path: path,
imgPath: imgPath,
imgName: imgName
};
menu[key] = addmenu;
}
$('#contentForJson').val(JSON.stringify(menu, "", 4));
$('#formMenu').submit();
});
Answer the question
In order to leave comments, you need to log in
but it seems to me that this code smells a bit like shit code (well, I don’t like passing json to value, input). Are there best practices on how to do this?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question