0

我在这里使用这个工具http://craftpip.github.io/jquery-confirm/#dialog并且我想要一个弹出窗口,它具有基于用于构建弹出窗口的一段数据的可变数量的按钮。

这是一个非常简单/空的示例。

$.confirm({
    title: 'testing',
    content: 'this has two static buttons',
    buttons: {
        confirm: function () {
        },
        cancel: function () {
        },
    }
});

我想要的是能够在“按钮:{...}”旁边放置一个foreach循环。

有没有办法这样做或实现我想要做的事情?

4

2 回答 2

0

只需在之前构建您的选项对象:

var options = {
    title: 'testing',
    content: 'this has two static buttons',
    buttons: {},
};

$.each( variable_name, function(){
    options.buttons[ this.btn_name ] = this.fn;
} );

$.confirm( options );

当然,一切都取决于您循环的对象的外观,但逻辑在这里。

于 2017-10-25T19:31:00.827 回答
0

Your logic is inverted. The following is an object:

{
    title: 'testing',
    content: 'this has two static buttons',
    buttons: {
        confirm: function () {
        },
        cancel: function () {
        },
    }
}

So you could do:

var options = {
    title: 'testing',
    content: 'this has two static buttons',
    buttons: {
        confirm: function () {
        },
        cancel: function () {
        },
    }
};
$.confirm(options);

You then can add items by

options.buttons["mybutton"] = function() { };

You can place the previous code in a loop and change the string "mybutton" to whatever you want for whatever functions you have. You're basically asking how to add a property to and existing javascript object.

于 2017-10-25T19:32:14.197 回答