1

I have some variables in sort-item.js file and want to trasfer them to js in html.

Here are the details: Because of Django CSRF protection when post data, I could only put the $ajax function in html like this:

<html>
<body>...</body>
<script>
    var post_data = {
        "name": "saveorder",
        "item_id": item_dataid,
        "from": from_index,
        "to": to_index,
        "order": order
    };
    $.ajax({
        type: 'POST',
        data: post_data,
        ...
    });
</script>
<html> 

Meanwhile I have got this below in sort-item.js and can show the data in console log:

var itemContainers = Array.prototype.slice.call(kanban.querySelectorAll('.board'));
itemContainers.forEach(function (container) {
.on('dragReleaseEnd', function (item) {
    ...
    var item_dataid = item.getElement().getAttribute('data-id');
    console.log(item_dataid);
    var order = muuri.getItems().map(item => item.getElement().getAttribute('data-id'));
    console.log(order);
})
.on('move', function (data) {
    var from_index = data.fromIndex;
    var to_index = data.toIndex;
    console.log(from_index + ' ' + to_index);
})
}

My question is how to transfer data.fromIndex, data.toIndex, order from sort-item.js to javascript variable post_data in html?

1 Answer 1

2

I have solved this problem by use a globle variable in sort-item.js.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.