2017-10-21 71 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)設置新的屬性