Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax for getting "options" values from $.widget( "ns.plugin" #741

Open
Jeff-Schafer opened this issue Dec 20, 2016 · 0 comments
Open

Syntax for getting "options" values from $.widget( "ns.plugin" #741

Jeff-Schafer opened this issue Dec 20, 2016 · 0 comments

Comments

@Jeff-Schafer
Copy link

Jeff-Schafer commented Dec 20, 2016

On the "Why Use the Widget Factory?" page, https://learn.jquery.com/jquery-ui/widget-factory/why-use-the-widget-factory/, the last example, what is the correct way to get the value of each "option"?

   $.widget( "ns.plugin", { 
       // Default options.
       options: {
           param1: "foo",
           param2: "bar",
           param3: "baz"
       },

       _create: function() {
           // Options are already merged and stored in this.options
           // Plugin logic goes here.
       } 
   });

Using this.options.param1 will get the correct value for this one entry, but a user should be able to get all of the values in options like an array.

Using the following code:

  $.each(this.options, function(key, value) {
     alert(key + ":" + value);
  });

returns:

  • classes:[object Object]
  • disabled:false
  • create:null
  • param1:foo
  • param2:bar
  • param3:baz

I expect the last 3 output, but not the first 3.

What is the proper syntax to just get:

  • param1:foo
  • param2:bar
  • param3:baz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants