2017-10-21 47 views
0

是否可以在tvml中使用相对链接?我从来没有遇到过在网页中使用它们的问题,但无法让它在我的tvml文档中工作。tvml中的相关链接?

从我的SWIFT:

static let TVBaseURL = "http://localhost:9001/" 

目前这从我的TVML它位于 “http://localhost:9001/templates/home.xml

<lockup onselect="getDocument('templates/Featured.xml')"> 
      <img src="http://localhost:9001/graphics/icons/ICON_featured.png" width="313" height="600" /> 
</lockup> 

注意,ONSELECT链接是相对的,工作正常工作。

但是这不起作用:

 <lockup onselect="getDocument('templates/Featured.xml')"> 
      <img src="../graphics/icons/ICON_featured.png" width="313" height="600" /> 
    </lockup> 

回答

0

这一切都取决于你如何定义你的getDocument功能。但是从您的代码中,很可能它看起来有点像official TVML Programming Guide, sec 8-3中的一个。

function getDocument(extension) { 
    var templateXHR = new XMLHttpRequest(); 
    var url = baseURL + extension; 

    loadingTemplate(); 
    templateXHR.responseType = "document"; 
    templateXHR.addEventListener("load", function() {pushPage(templateXHR.responseXML);}, false); 
    templateXHR.open("GET", url, true); 
    templateXHR.send(); 
} 

它使用像您的代码一样的预设baseURL。因此,你的文档支持相关链接。 (而不是通用链接,把完整的http://localhost:9001/index.xml将打破它。)

在这个例子中,XMLHttpRequest对象open函数,采取完整的网址,而不是相对的一个。阅读更多关于XMLHttpRequest open here

总之。这里没有任何关系。

但是,您可以使用Javascript的功能做类似的事情。

当您获取XML文档时,您可以找到document.getElementsByTagName("img")的所有标签,它给出了图像元素的列表。然后,只需要用.item(i)来查看它们中的每一个,通过.getAttribute('src')获取它们的源属性,看看它是以http还是https开头,如果不是,则通过.setAttribute('src', baseUrl+imagePath)设置新的属性