V
V
Vasya Surname2018-12-22 23:55:45
Programming
Vasya Surname, 2018-12-22 23:55:45

How to change the value of a global variable in callbacks?

....
 var idResource = 1;
 
$R('#content', {
  autosave: '/assets/tmp/redactor/add/autosave.php',
        autosaveData: {
            id: idResource,
            elements: '#pagetitle'
        },
  callbacks: {
     autosave: function(name, data, response)
         {
         idResource =  response;  // не меняется значение переменной  при повторном autosave . 
...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Albert, 2016-03-01
@Northsoft

"else" always refers to the same branch. If you wrote "else" after the last branch, then the second branch will also apply to it.
When designing mutually exclusive options (for example, when a part cannot be both first-class and defective at the same time), it is recommended to use the following design:

if (clause1) {
  action1;
} else if (clause2) {
  action2;
} else {
 action3;
}

P
Pavel Kornilov, 2018-12-23
@KorniloFF

window.idResource =  response; 
console.log('window.idResource = ', window.idResource);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question