Bug Tracker

Modify

Ticket #7066 (closed enhancement: wontfix)

Opened 3 years ago

Last modified 3 years ago

More streamlined technique of appending a list

Reported by: davehamptonusa Owned by:
Priority: undecided Milestone: 1.4.3
Component: manipulation Version: 1.4.2
Keywords: Cc:
Blocking: Blocked by:

Description

Currently, you can append a list of $objects or html like this: Lets assume:

bar2 = $('<div>helo there</div>');

bar3 = $('<div/>', { text: 'text3'});

bar4 = $('<div/>', { text: 'text4'});

bar5 = $('<div/>', { text: 'text5'});

foo = [bar2, bar3, bar4, bar5];

body = $('body');

body.append(bar2, bar3, bar4, bar5);

Arguably, this is cumbersome and requires some contortions in certain situations.

You can also do this: body.append.apply(body, $.isArray(foo) ? foo : [foo]);

This is also somewhat counterintuitive.

It would be more convenient if you could do this: body.append(foo);

This currently fails, but could be allowed if jquery.clean were altered to include

if ( jQuery.isArray( elems[0] ) ) {

elems = elems[0];

}

after the var declaration. This would stay backward compatible with the apply technique.

I ran the test suite against this and it appeared to function normally, although honestly, I know I wasn't running it correctly.

Why the change? First its nice sugar.

Second, in use its faster than looping over an append(which many people do).

Why say no?

Maybe you have plans for some way cooler use for an array.

It does add an additional check to every call to clean - so it slows a few things down.

Change History

comment:1 Changed 3 years ago by snover

  • Priority set to undecided

And how much faster is this than simply putting the elements themselves into the array by [ bar2[0], bar3[0], bar4[0], bar5[0] ] and then appending the array?

comment:2 Changed 3 years ago by snover

  • Status changed from new to closed
  • Resolution set to wontfix

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.