Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays in JavaScript

 
Madhav Kanneganti
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm wonder to know how to build an array just like the following dynamically. i.e. Im doing a multi columns sorting and from the child window after we selected multiple columns with their order the results should be populated like this.

I was building like this
Here rowCount is number of columns that we selected from the table and resArray is an array.
Is this right way Im building?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than using arrays in arrays, I'd make each array element an object with two properties rather than a 2-element array. Makes everything much neater and easier to understand.
 
Madhav Kanneganti
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

I'm using jquery table sorter api to do multi columns sorting and this api needs the array like this, hence I was requesting how to build dynamically. Would your suggestion applicable to my request?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should have explained that to begin with. If that's what the plugin needs, you can't change it.

What specific problems are you having?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI: In HTML4, ids really should not begin with a number. Some browsers have issues with that.

Also the selector $("input:radio[id="+i+"_order]:checked") is a waste. You are making it slower, just select the id!

Personally I would do something more like



>
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic