S
S
starkos2015-09-14 14:28:25
.NET
starkos, 2015-09-14 14:28:25

Get value from callback - JS functions?

I began to deal with js callback functions, but so far not very understanding. Please, give advice on the example of such an implementation:
there is a piece of code:

// функция удаления чего-либо
var deleteAction = function (item) {
            ...
            // диалоговое окно с двумя кнопками
            $(document).сonfirm({
                message: 'Удалить?',
                callbackY: function () {
                   // действия при нажатий кнопки - да
                    return true;
                },
                callbackN: function () {
                   // действия при нажатий кнопки - нет
                    return false;
                }
            });
            ...
};


so, from calbackY or calbackN must return to the deleteAction function or true or false, and depending on what is returned, the deleteAction function will already perform the action.

how to return values ​​from callbackY or callbackN for deleteAction function?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
Ascar, 2019-04-15
@Sneiksus

Depends on the size, if there is a lot of data then EF + sql lite, if it is not enough then serialize the dictionary and save it to a file:

var str = JsonConvert.SerializeObject(new Dictionary<string, string> {
               { "key","value"},
                { "key2","value2"}});

            File.WriteAllText("config.json", str);

            str = File.ReadAllText("config.json");

            var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(str);

D
Dmitry Bashinsky, 2019-04-15
@BashkaMen

If you have winforms there is Settings
https://www.codeproject.com/Articles/15013/Windows...
I think there are analogues everywhere + to implement a similar thing 5-10 minutes

A
Alexander, 2019-04-15
@alexr64

Serialization. In xml/json/binary.
And what? sqlite.

P
Peter, 2019-04-15
@Morpheus_God

In the registry, a binary file.

R
Roman Mirilaczvili, 2019-04-15
@2ord

"value-key" is better to be stored in specialized stores like FASTER .

D
Denis Ineshin, 2015-09-14
@IonDen

This is where jQuery and callbacks are not needed at all:

var conf = window.confirm('Удалить?');
console.log(conf); // true, если ок. false, если отмена

if (conf) {
    // удаляем
} else {
    // не удаляем
}

// UPD.
// если же у вас диалоговое окно не стандартное,
// то вы не можете просто вернуть значение, так как оно будет асинхронным.
// В этом случае вы должны вызывать нужную функцию напрямую. Вот так:

function myDeleteFunction () {
    // тут удаляем
}

function myCancelFunction () {
    // тут отмена
}

$(document).сonfirm({
    message: 'Удалить?',
    callbackY: myDeleteFunction,
    callbackN: myCancelFunction
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question