Why doesn't the mixin work as expected?

  • 0
    Pseudocode. We fill the select-list with options:
    foo: function() {
    	return new Promise((resolve, reject) => {	
    		$.ajax({
    			// ....
    			success: function (data) {
    				if (data.length) {
    					for (var e in data) {
    						select.appendChild(option);
    					}
    
    					resolve(data);
    				}
    			},
    			error: function (xhr, textStatus, errorThrown) {
    				reject(textStatus);
    			}
    		});
    	});
    },


    client code:

    fool().then(result => {
                console.log($('#my_select').find('options').length)
            }).catch(reason => {
    
            }).finally(() => {
                console.log($('#my_select').find('options').length)
            });


    I expect that the promise will resolve resolve ONLY when the code to populate the list is executed, but the console shows in both cases that the option's in #my_select = 0

    Why is that?
    JavaScript Anonymous, Jun 18, 2019

  • 1 Answers
  • 0
    You have a typo.

    & gt; .find ('options')

    options tag does not exist
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!