0

我正在尝试关注这篇文章,他在其中描述了使用的婴儿步骤

在本节中,他试图描述如何从一个页面跳转到另一个页面。我想看看我是否可以做 4 级,但不知道怎么做;这也可能是一个纯 JS 问题。

> App.onLaunch = function(options) {
>     alert("Hello!", function() {
>       var helloDocument = getDocumentContents("http://localhost:8000/hello.tvml", function(xhr)
> {
>         navigationDocument.dismissModal();
>         navigationDocument.pushDocument(xhr.responseXML);
>       });
>     }); }

有没有人帮忙,怎么回调?

> App.onLaunch = function(options) {
>     alert("Hello!", function() {
>       var helloDocument = getDocumentContents("http://localhost:8000/hello.tvml", function(xhr)
> {
>         navigationDocument.dismissModal();
>         navigationDocument.pushDocument(xhr.responseXML);
>       });
>     }); }
4

1 回答 1

0

要导航到其他页面,您需要将这些页面推送到堆栈中:

var parser = new DOMParser();
var newPageDocument = parser.parseFromString(NEW_PAGE_XML, 'application/xml');
navigationDocument.pushDocument(newPageDocument);

要返回上一页,可以按遥控器上的Menu按钮或调用navigationDocument的popDocument方法:

navigationDocumemt.popDocument();

假设 getDocumentContents 是从 hello.tvml 获取 XML 的方法,您的代码如下所示:

App.onLaunch = function(options) {
  getDocumentContents("http://localhost:8000/hello.tvml", function(response) {
    var parser = new DOMParser();
    var firstDocument = parser.parseFromString(response, 'application/xml');
    navigationDocument.pushDocument(firstDocument);
  });
}

此外,不支持警报,但控制台支持。

于 2015-09-15T15:49:41.877 回答