«Глобальные» переменные javascript являются членами объекта window. Вы можете получить доступ к ссылке в качестве члена объекта window.
var v = "initialized";
function byref(ref) {
window[ref] = "changed by ref";
}
byref((function(){for(r in window){if(window[r]===v){return(r);}}})());
// could also be called like... byref('v');
console.log(v); // outputs changed by ref
Обратите внимание, что приведенный выше пример не будет работать для переменных, объявленных внутри функции.
В '{{ (path('change_todo_status', {'todo_id': todoId})) }}'
ветка ожидает переменную ветки. У меня уже была эта проблема, и я использовал замену в javascript для замены.
В примере:
let todoId = cb.getAttribute('data-id');
/*
* this will generate a path with ReplaceMeWithCorrectValue instead of the correct value.
* You have to use a placeholder that correspond to the restrictions defined in your route.
*/
let url = "{{ (path('change_todo_status', {'todo_id': 'ReplaceMeWithCorrectValue'})) }}";
url = url.replace("ReplaceMeWithCorrectValue", todoId);
А затем, в вашем Ajax:
$.ajax({
url: url,
// the remain of your code