我是NativeScript的新手,我正在尝试使用FancyAlert NPM模块:
https://github.com/NathanWalker/nativescript-fancyalert
在他们的自述文件中,他们使用TypeScript显示了一个非常简单的示例,如下所示:
import { TNSFancyAlert, TNSFancyAlertButton } from "nativescript-fancyalert";
.
.
.
public showSuccess() {
TNSFancyAlert.showSuccess(
"Success!",
"Fancy alerts are nice.",
"Yes they are!"
);
}
在他们的XML文件中,他们只是像平常一样调用它:
<Button text="Alert Success" tap="{{showSuccess}}" />
所以我没有使用TypeScript。我无法让这个简单的警报工作。我试过了:
在我的main-view-model.js中
const fancyAlert = require("nativescript-fancyalert");
.
.
.
fancyAlert.showSuccess(
"Success!",
"You are logged in.",
"Success!"
);
不工作
任何人都可以帮我使用核心JS使用这个模块吗?
谢谢。
尝试:fancyAlert.TNSFancyAlert.showSuccess()
。
[编辑]这真的应该有效,因为它是你的问题中由Narendra Mongiya联系的issue filing中给出的解决方案的一面镜子。要记住的一件事是它是一个Promise,所以让我们在那里添加一个catch()
块来揭示任何错误。
const fancyAlert = require("nativescript-fancyalert");
// ...
fancyAlert.TNSFancyAlert.showSuccess(
"Success!",
"You are logged in.",
"Success!"
)
.then((resolution) => {
console.log("[TNSFancyAlert] showSuccess() succeeded.", resolution);
})
.catch((error) => {
console.error("[TNSFancyAlert] showSuccess() failed.", error);
});
您可能还会发现您只是在代码中的错误位置调用它。