【发布时间】:2016-05-31 16:07:57
【问题描述】:
我一直在查看有关如何使用 Promise 的各种讨论,但我没有得到任何工作。
我不断收到错误消息“无法读取未定义的属性。”
“那么”、“完成”等是 Javascript 内置的吗?还是他们要求我包含其他一些外部脚本?
这是我最近尝试使用 2 个简单的对话框(确认和拒绝都是简单的对话框):
var confirmWithPromise = Confirm();
var reject = confirmWithPromise.then(Reject("This record cannot be deleted."));
如果我可以从最简单的方法开始让我的示例工作,我想我可以从那里开始。
谢谢。
更新:这是我的 Confirm() - 它没有返回承诺。我不完全明白如何实现它的返回:
function Confirm() {
var buttons = [
{
text: "Yes",
//icons: {
// primary: "ui-icon-heart"
//},
click: function () {
$(this).dialog("close");
callback(true);
}
// Uncommenting the following line would hide the text,
// resulting in the label being used as a tooltip
//showText: false
},
{
text: "No",
//icons: {
// primary: "ui-icon-heart"
//},
click: function () {
$(this).dialog("close");
callback(false);
}
// Uncommenting the following line would hide the text,
// resulting in the label being used as a tooltip
//showText: false
}
];
showDialog("Confirm", "Are you sure? Once the record is deleted, it cannot be recovered.", buttons);
}
【问题讨论】:
-
Confirm是否返回了一个 Promise?function Confirm() { return new Promise(...); } -
错误似乎很明显:
Confirm不返回任何内容。 ““那么”、“完成”等是 Javascript 内置的吗?” Promise 是 JavaScript 的一部分,是的。 -
如果您提供了确认代码,我们可以看到它返回的内容
标签: javascript promise