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 7685909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:21:27+00:00 2026-05-31T19:21:27+00:00

I am passing a JSON object as a reference to my custom jquery widget

  • 0

I am passing a JSON object as a reference to my custom jquery widget like this:

 var jsonData =  { "Name": "John ", "Country": "US" };

 $("#testdiv").TestWidget({MyData:jsonData});

And in my widget, I am changing the data like this:

$.widget("my.TestWidget", {

    options: {
        MyData: null
    },
    _create: function () {
    this.options.MyData.Name = "NewName";

    }
});

But, the change is not reflected in the original JSON data because apparently jQuery is creating a copy of my JSON data when creating the widget!

This is very undesirable. Is there any way to prevent copying of data and instead pass the object as reference?

Above is a simplified version of our original scenario.

Thanks

  • 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-05-31T19:21:29+00:00Added an answer on May 31, 2026 at 7:21 pm

    I’m afraid this is not possible. Looking at the jQuery UI source code, you can see why:

    _createWidget: function( options, element ) {
        // $.widget.bridge stores the plugin instance, but we do it anyway
        // so that it's stored even before the _create function runs
        this.element = $( element ).data( this.widgetName, this );
        this.options = $.extend( true, {},
                this.options,
                $.metadata && $.metadata.get( element )[ this.widgetName ],
                options );
    
        var self = this;
        this.element.bind( "remove." + this.widgetName, function() {
                self.destroy();
        });
    
        this._create();
        this._init();
    },
    

    The options is being copied using the $.extend method.

    Personally, I don’t see a reason why you would want to pass jsonData as a reference here. It seems to me that there’s something wrong with your design. Could you provide more information on that matter?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue with passing the generated JSON notation of my object to
Let's say I have an object MyObject that looks like this: public class MyObject
I'm passing a JSON object to Javascript via the ViewBag with the following code
I'm struggling with passing a JSON object to a .swf via FlashVars and decoding
I am passing back a JSON object (consisting of an array of strings) from
In a edit page, I am passing the domain object as JSON object to
I would like to pass the JSON object along with the view when I
I'm working on a RoR project and I am passing a JSON object to
From a previous question on Stackoverflow Iterating through/Parsing JSON Object via JavaScript .... My
I need help in retrieving a JSON object and parsing the array into my

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.