使用JavaScript将Metro绑定到Metro风格应用中的ListView [英] Bind XML to ListView in metro style app with JavaScript

查看:92
本文介绍了使用JavaScript将Metro绑定到Metro风格应用中的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

b


 我使用JavaScript创建了一个metro风格的应用程序。在我的应用程序中,我调用一个返回xml的api。  我使用以下代码解析xml,结果显示在我的html页面中。

Hi,

 I created a metro style app using JavaScript. In my application i am calling an api that returns a xml.  I used the following codes to parse a xml and the result is successfully displayed in my html page.

function loadRemoteXhr() {

        document.getElementById("xhrOutput").innerHTML = "";
      
        
       WinJS.xhr({
            url: "http://api.eventfinder.co.nz/categories/list",
            user: 'xxxxx',
            password:'xxxxx'
        }).then(
            xhrParseXml, xhrError
            );

            
    }
function xhrParseXml(result) {

     

        var outputArea = document.getElementById("xhrOutput");
        var xml = result.responseXML;

       
        if (xml) {
           
            var items = xml.querySelectorAll("categories > category");
            if (items) {

                var length = Math.min(10, items.length);
                for (var i = 0; i < length; i++) {
                    var link = document.createElement("a");
                    var newLine = document.createElement("br");
                   
                    link.setAttribute("href", xml.getElementsByTagName("category")[i].childNodes[0].nodeValue);

                    link.innerText = (i + 1) + ") " + xml.getElementsByTagName("category")[i].childNodes[0].nodeValue;
               

                    var _maincategory = xml.getElementsByTagName("category")[i].childNodes[0].nodeValue;

                                      

                    outputArea.appendChild(link);
                    outputArea.appendChild(newLine);
                }
            } else {
                outputArea.innerHTML = "There are no items available at this time";
            }
        } else {
            outputArea.innerHTML =
                "Unable to retrieve data at this time. Status code: " + statusCode;
        }
    }

推荐答案

不是没有直接。 虽然这很容易将这些数据读入列表中吗? 就这样做!

No not directly.  It is easy to read this data into a list though right?  Just do that!

-Jeff


这篇关于使用JavaScript将Metro绑定到Metro风格应用中的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆