1

Have a controller class setup as a widget. Labeled here as "buttonController". I'm trying to call and instantiate an instance of the controller widget per each button. Everything seemingly works, except that the loop apparently is not calling 3 instances, but resetting the same widget with the last bit of data. Meaning the options are only being set as the last object in buttons. Feel either you can not call the widget more than once, or my loop is not doing what I expect. Any thoughts?

define([
    'jquery',
    'underscore',
    'buttonController',
    'jquery/ui',
    'jquery/jquery.parsequery'
], function ($, _, ButtonController) {
    'use strict';

    $.widget('mage.supplementalbuttons', {
        options: {
            spConfig: {},
            superSelector: '.supplemental-super-attribute-select',
            selectSimpleProduct: '[name="selected_configurable_option"]',
            state: {},
            containerSelector: '#supplemental-configurable',
            buttonSelector: '',
            formSelector: '#supplemental-configurable form',
            skuSelector: '.supplemental-sku',
            action: '',
            buttons: {}
       },

       /**
        * Creates widget
        * @private
        */
       _create: function () {
           // Initial setting of various option values
           this._initialize();

           $(this.element).trigger('supplementalbuttons.initialized');
       },

        /**
         * @private
         */
        _initialize: function () {
            var options = this.options;
            var element = this.element;
            var buttons = options.buttons;
            $.each(buttons, function(key, value){
              var buttonController = new ButtonController;
              var buttonSelector = "button#" + key + "-" + value.sku;
              buttonController.element = element;
              buttonController.options = options;
              buttonController.options.spConfig = value.spConfig;
              buttonController.options.action = value.action;
              buttonController.options.buttonSelector = buttonSelector;
              buttonController._create();
            });
        }


    });

    return $.mage.supplementalbuttons;
});

0

Your Answer

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

Browse other questions tagged or ask your own question.