我正在使用toastr并希望使用从 ajax 调用返回的 json 对象设置选项。我在动态设置选项属性和值时遇到了一些麻烦。这是示例代码:
if(data.toast){
$.each(data.toast, function(index, element) {
toastr.options.index = element;
});
}
data.toast 是一个 json 对象,如下所示:
"toast":{"closeButton":true}
如果我硬编码它会是什么样子:
toastr.options.closeButton = true;
我应该将迭代器中的 .index 更改为什么,以便它将其评估为变量