用对象覆盖jQuery ui小部件字符串选项 [英] overriding a jquery ui widget string option with an object
问题描述
我想让一个jQuery ui小部件选项默认为字符串,但是我希望它能够被一个对象覆盖.当我这样做时,我实际上是以某种奇怪的方式将字符串转换为对象,然后使用我传入的任何对象进行扩展.
I want to have a jquery ui widget option be a string by default, but I want it to be able to overridden by an object. When I do this, I actually get the string converted to an object in some strange way, and then extended with whatever object I pass in.
$.widget("ui.test", {
options: {
anOption: "a,b,c"
},
_create: function() {
console.log(this.options);
}
});
$('div').test({
anOption: {
a: 'A'
}
});
如果我跳过将选项传递给小部件的操作,它将在_create方法中作为字符串接收.如果我传入一个对象,就会发生奇怪的行为.在chrome js控制台日志中,我得到了这个,这不是我想要的.
If I skip passing in the option to the widget, it will be received as a string in the _create method. If I pass in an object, the strange behavior occurrs. In chromes js console log I get this, which is not what I want.
Object
anOption: Object
0: "a"
1: ","
2: "b"
3: ","
4: "c"
a: "A"
我该如何解决?
jsfiddle: http://jsfiddle.net/MatteS75/s9wK2/
jsfiddle: http://jsfiddle.net/MatteS75/s9wK2/
推荐答案
这是一个最近已修复的错误:
This is a bug that has been fixed very recently:
http://bugs.jqueryui.com/ticket/8713
https://github.com/jquery/jquery-ui/commit/9b908878ae3a9c0fbbd9958b579f223a648 /a>
https://github.com/jquery/jquery-ui/commit/9b908878ae3a9c0fbbd9958b579f223a648c5c69
这篇关于用对象覆盖jQuery ui小部件字符串选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!