嘿,我在这里创建一个jquery插件,其默认设置为
var settings = {
renderTo:'body',
width: 800,
height:900,
url:'miserables.json',
zoom:true,
loadingText:"loading...",
margin:{
top: -5,
right: -5,
bottom: -5,
left: -5
}
};
所以当我将此设置覆盖为
时$(function(){
$('#diagram').renderSvg({
renderTo: '#diagram', // THIS IS WORKING
height:500, // THIS IS WORKING
width:200, // THIS IS WORKING
url:'check.json' //THIS IS NOT WORKING INSTEAD OF I'M GETTING DEFAULT URL
});
});
所以如何覆盖网址。请帮帮我。提前致谢
答案 0 :(得分:1)
通常,您使用自定义设置扩展默认选项。为此,请将settings
初始化移至renderData
函数,并从renderSvg
调用它,如:
this.renderData(options);
所以代码将成为:
$.fn.renderData = function (options) {
var options = $.extend({}, {
renderTo: 'body',
width: 800,
height: 900,
url: 'miserables.json',
zoom: true,
loadingText: "loading...",
margin: {
top: -5,
right: -5,
bottom: -5,
left: -5
}
}, options);
console.log(options.url);
// ...
};
和
$.fn.renderSvg = function (options) {
this.renderData(options);
// ...
};