覆盖窗口小部件上的默认选项

时间:2012-01-27 11:02:07

标签: jquery

我有以下小部件,我想在初始化小部件时设置footerText选项,如何做到这一点?

$.widget("ui.pdf", {
    options: {
        // Service address 
        address: "http://localhost:18362/PDFService.svc/GetPDFWithHeaderAndFooter",
        //address: "http://test.test.com/PDFService.svc/GetPDFWithHeaderAndFooter",
        orientation: "Landscape",
        headerUrl: "http://www.test.com/clients/test/test.html",
        footerText: "Test",
        url: "http://www.test.com/portfolio-manager-1/test-test-portfolio1?pdf" //"http://www.test.com/agents-app/test-portfolio-12-01-12-0853" //"http://www.test.com/portfolio-manager-1/test-test-portfolio1" //window.location.href //"http://www.soccernet.com"
    },
    _create: function () {
        var el = this.element;
        var o = this.options;
        $.getScript("http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.js",
            function () {
                $.template("link", '<a href="${pdfUrl}">download pdf</a>');
                $.ajax({
                    url: o.address,
                    data: { orientation: o.orientation, headerUrl: o.headerUrl, footerText: o.footerText, url: o.url },
                    dataType: "jsonp",
                    success: function (result) {
                        this.valueTable = $.tmpl("link", result).appendTo(el);
                        $("#loading").hide();
                    }
                });
            });
    },
    destroy: function () {
        this.valueTable.remove();
        $.widget.prototype.destroy.apply(this, arguments); // default
    }
});
})(jQuery);

2 个答案:

答案 0 :(得分:1)

$(someSelector).pdf({footerText: "someText"});

答案 1 :(得分:1)

只需将选项对象传递给插件的方法:

$('#myelement').pdf({
    footerText: 'New footer text'
});