This is a migrated thread and some comments may be shown as answers.

Custom widget array value in options not being set as expected

2 Answers 45 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brian Vallelunga
Top achievements
Rank 1
Brian Vallelunga asked on 18 May 2012, 06:59 PM
I have a custom widget that receives options. On of the options is an array of strings. By default the array value in the options, as defined in my widget, has six values. When instantiating the widget, the end user can supply his own array to override these values. Instead of replacing the entire array, each value passed replaces the default value, leaving a total of six still, even if only one value is passed.

Here's some pseudocode:

// Defined in the widget as defaults
options: {
    intervals: ["Day", "Month", "Quarter", "Year"]
}
  
// Later, when creating my widget
$("#widget").kendoMyWidget({
    intervals: ["Month"]
});

What I would expect is that after calling Widget.fn.init.call(that, element, options) in my widget, that options.intervals array would only contain "Month". Instead it contains: "Month", "Month", "Quarter", "Year". Any thoughts on this?

2 Answers, 1 is accepted

Sort by
0
Accepted
Petyo
Telerik team
answered on 19 May 2012, 11:42 AM
Hello,

This is how jQuery extend(deep) (which kendo uses) method works. 

$.extend(true, { foo: ['foo', 'bar'] }, {foo: ['bar'] }).foo; // 'bar', 'bar'

Greetings,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian Vallelunga
Top achievements
Rank 1
answered on 21 May 2012, 07:59 PM
Interesting, thanks. I've had to just manually set the options in code after the initialization is done. Easy enough of a workaround, but I'm surprised at the default behavior.
Tags
General Discussions
Asked by
Brian Vallelunga
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Brian Vallelunga
Top achievements
Rank 1
Share this question
or