0

I've created (or am trying to create) a jQuery UI widget using the widget factory and have set up my _setOptions method this way as found here: http://wiki.jqueryui.com/w/page/12137708/How%20to%20use%20jQuery%20UI%

_setOptions: function (key, value) {
    if (this.options[key] !== value) {
        this.options[key] = value;
        this._update();
    }
},

This is my options object:

 options: {
            title: 'Legend',
            colors: ['#0000CC', '#6600CC', '#009900', '#990000', '#6600FF', '#CCFF00', '#FF9900', '#000000', '#FFFFFF', '#00FF00'],
            items: undefined
        }

However, when I pass in a new title value for my legend widget, I am getting an object for key instead of a key and value in _setOptions. value comes in undefined, for the record.

$('#myLegend').legend('option', 'title', 'New Title');

The key object

My expectations were this:

key==='title'
value==='New Title'

If there some common misconception I'm missing or can anyone think of why this would be happening?

4

1 回答 1

1

_setOptions方法确实使用第一个参数的对象调用,它包含所有更改的选项的键/值对。

http://api.jqueryui.com/jQuery.widget/#method-_setOptions

你可能打算使用的是_setOption而不是_setOptions

于 2013-01-28T19:43:17.137 回答