Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8407555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:23:53+00:00 2026-06-09T23:23:53+00:00

I’m building my first jQuery plugin. It takes JSON data and loads it into

  • 0

I’m building my first jQuery plugin. It takes JSON data and loads it into table. I’ve got most of the logic done, I’m just having trouble building the default options array.

What I would like to do is pass in an options array like this:

/* Column array format:
    cols:
    [colname:
    {
        title: 'Column Title',  // Column title for display (if not specified, will
                                // use 'colname' value instead.
        sorttype: 'text',       // 'text', 'dropdown' or 'none'
    },
    nextcolname:
    {
        ...
    },
    ...
    ]
*/

What I’m having problems with is packing the default array if no options are passed in. Here’s what I have:

var settings = $.extend ({
    'cols'      : 'auto',
    'sortable'  : 'true' //turn off sorting altogether with this option.
}, options);

var index = '';
var element = '';
var colname = '';

// No columns specified.  That's OK, grab keys from first JSON element.
if (settings.cols == 'auto')
{
    settings.cols = Object.keys(data[0]); 

    $.each(settings.cols, function(index, colname){
        settings.cols[colname].title = colname;
        settings.cols[colname].sorttype = 'text';
    })
}

First of all, style-wise, does it look like I’m going about this the right way? Do both the format of the options array and the way I’m parsing it make sense? Second of all, the settings.cols[colname].title returns a type error because it doesn’t exist (of course). How do I populate this object so I can use it effectively so that I can iterate through it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:23:54+00:00Added an answer on June 9, 2026 at 11:23 pm

    The line where you assign settings.cols isn’t going to work … it assigns an array rather than a property map. Try this instead:

    var keys = Object.keys(data[0]);
    for (var i in keys) settings.cols[keys[i]] = {};
    

    Here’s a complete test that shows the difference. settings1 comes out valid using the above, but trying to access settings2 throws an error:

    var data = { a: 1, b: 2, c: 3 };
    var keys = Object.keys(data);
    var settings1 = { cols: {} };
    var settings2 = { cols: {} };
    for (var i in keys) settings1.cols[keys[i]] = {title: "hi"};
    settings2.cols = Object.keys(data);
    alert(settings1.cols["b"].title);
    alert(settings2.cols["b"].title);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.