4

I have created one custom tab section in customer dashboard area in back end.

enter image description here

In this section i have called one phtml file, in this phtml i want to load on js using magento x-init.

Please check below code.

<script type="text/x-magento-init">
    {
        "*": {
            "#magearray-attachments": {
                "magearrayFileUploadTwo": {
                }
            }
        }
    }
</script>

But, problem is js is not loading when i click on my custom tab "View Attachments". I have also assigned js in requirejs-config.js.

Can anyone help me with this?

1

On page load, Magento is going to consume and initialize every data-mage-init and <script type="text/x-magento-init"> it can find in the DOM tree. Since your page is loaded through Ajax, Magento already went through the DOM tree. You're going to need to trigger the 'initializing process' manually.

You can do this by trigger the contentUpdated event on your element like so $(#selected).trigger('contentUpdated').

  • Can your please share the code? Because i couldn't understand exactly. – Ronak Mar 8 at 10:08
  • Thanks i have add trigger and now it's working. – Ronak Mar 8 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.