Answer the question
In order to leave comments, you need to log in
How to organize news selection from the list (JavaScript + RSS or HTML parser)?
I parse data from the server using an HTML or RSS parser.
Each entry has a common CSS style id and a unique ID passed to the JS function (in the class="id" or date-id="id" attribute);
But since this data is loaded from the server or set in the JS code itself, the function that tracks clicks on these records to navigate using WinJS.Navigation.navigate does not work.
Actually, how to make the function for tracking clicks on data loaded from outside in the same JS file work? I write in Visual Studio under Windows Market.
Click tracking function:
function ToStory(eventInfo) {
var link = eventInfo.target;
var storyid = link.className;
if ((storyid == '') || (storyid == 0)) {
WinJS.Navigation.back(10).done();
} else {
WinJS.Navigation.navigate("/pages/story/story.html");
}
}
function loadRemoteXhr() {
document.getElementById("topstory").innerHTML = "";
WinJS.xhr({ url: "ссылка на RSS" }).then(
xhrParseXml, xhrError
);
}
function xhrParseXml(result) {
var outputArea = document.getElementById("topstory");
var xml = result.responseXML;
if (xml) {
var items = xml.querySelectorAll("rss > channel > item");
if (items) {
var length = Math.min(10, items.length);
for (var i = 0; i < length; i++) {
var link = document.createElement("li");
link.setAttribute("id", "tostory");
link.setAttribute("class", items[i].querySelector("link").textContent);
link.innerText = items[i].querySelector("title").textContent;
outputArea.appendChild(link);
}
} else {
outputArea.innerHTML = "There are no items available at this time";
}
} else {
outputArea.innerHTML = "Unable to retrieve data at this time. Status code: " + statusCode;
}
}
function xhrError(result) {
var statusCode = result.status;
var outputArea = document.getElementById("topstory");
outputArea.innerHTML = "Unable to retrieve data at this time. Status code: " + statusCode;
}
//RSSload
loadRemoteXhr();
//Навигация
tostory.addEventListener("click", ToStory, false);
<div id="blocks">
<div id="blocktit">Популярные истории</div>
<ul id="topstory"></ul>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question