webix列表无法显示外部xml文件数据

时间:2016-11-01 01:53:15

标签: javascript xml list webix

我有一个webix列表,我试图加载外部xml文件的数据。我无法让这个工作,并尝试了一切。代码如下:

<!DOCTYPE html>
    <html class="gr__docs_webix_com"><head>
    <meta http-equiv="content-type" content="text/html; charset=utf8">
            <title>Loading from an external data file</title>
            <script type="text/javascript" src="http://cdn.webix.io/edge/webix.js"></script>
            <link rel="stylesheet" type="text/css" href="http://cdn.webix.io/edge/webix.css">       

        <body >
            <div class="header_comment">Loading from an external data file (xml, json etc.)</div>           

            <div id="testB"></div>

            <script type="text/javascript" charset="utf-8">

            webix.ui({
                    container:"testB",
                    view:"datatable",                        
                    columns:[

                        { id:"name",    header:"Genre",width:200},
                        { id:"count",   header:"Count" , width:200},

                    ],
                    autoheight:true,
                    autowidth:true,

                    datatype:"xml",
                    url:'genrelist.xml'
                }); 

            </script>


    </body>
    </html>

外部xml文件(genrelist.xml)内容如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<genrelist><genre name="00s" count="19"/><genre name="30s" count="2"/><genre name="40s" count="15"/><genre name="50s" count="31"/><genre name="60s" count="144"/><genre name="70s" count="160"/><genre name="80s" count="576"/><genre name="90s" count="219"/><genre name="Acid House" count="4"/><genre name="Acid Jazz" count="27"/><genre name="Acoustic Blues" count="605"/><genre name="Adult" count="189"/><genre name="Adult Album Alternative" count="19"/><genre name="Adult Alternative" count="94"/><genre name="Adult Contemporary" count="204"/><genre name="African" count="191"/><genre name="Afrikaans" count="9"/><genre name="Alt Country" count="11"/><genre name="Alternative" count="630"/><genre name="Alternative Folk" count="8"/><genre name="Alternative Rap" count="6"/><genre name="Ambient" count="414"/><genre name="Americana" count="36"/><genre name="Anime" count="31"/><genre name="Anniversary" count="0"/><genre name="Arabic" count="144"/><genre name="Asian" count="153"/><genre name="Avant Garde" count="6"/><genre name="Bachata" count="24"/><genre name="Banda" count="29"/><genre name="Barbershop" count="4"/><genre name="Baroque" count="90"/><genre name="Best Of" count="142"/><genre name="Big Band" count="7"/><genre name="Big Beat" count="9"/><genre name="Birthday" count="0"/><genre name="Black Metal" count="64"/><genre name="BlogTalk" count="12"/><genre name="Bluegrass" count="54"/><genre name="Blues" count="1116"/><genre name="Bollywood" count="26"/><genre name="Bop" count="18"/><genre name="Bossa Nova" count="34"/><genre name="Brazilian" count="93"/><genre name="Breakbeat" count="68"/><genre name="British Invasion" count="0"/><genre name="Britpop" count="93"/><genre name="Bubblegum Pop" count="1"/><genre name="Cajun and Zydeco" count="9"/><genre name="Caribbean" count="49"/><genre name="Celtic" count="42"/><genre name="Celtic Rock" count="11"/><genre name="Chamber" count="23"/><genre name="Chicago Blues" count="7"/><genre name="Chill" count="408"/><genre name="Chinese" count="7"/><genre name="Choral" count="14"/><genre name="Christian" count="1755"/><genre name="Christian Metal" count="6"/><genre name="Christian Rap" count="12"/><genre name="Christian Rock" count="95"/><genre name="Christmas" count="237"/><genre name="Classic Alternative" count="15"/><genre name="Classic Christian" count="9"/><genre name="Classic Country" count="60"/><genre name="Classic Jazz" count="65"/><genre name="Classic Metal" count="3"/><genre name="Classic R&amp;B" count="69"/><genre name="Classic Rock" count="633"/><genre name="Classical" count="637"/><genre name="Classical Period" count="10"/><genre name="College" count="173"/><genre name="Comedy" count="105"/><genre name="Community" count="148"/><genre name="Contemporary Bluegrass" count="0"/><genre name="Contemporary Blues" count="4"/><genre name="Contemporary Country" count="14"/><genre name="Contemporary Folk" count="8"/><genre name="Contemporary Gospel" count="17"/><genre name="Contemporary R&amp;B" count="13"/><genre name="Contemporary Reggae" count="22"/><genre name="Cool Jazz" count="13"/><genre name="Country" count="717"/><genre name="Country Blues" count="181"/><genre name="Creole" count="23"/><genre name="Cumbia" count="126"/><genre name="Dance" count="1716"/><genre name="Dance Pop" count="128"/><genre name="Dancehall" count="130"/><genre name="Dancepunk" count="4"/><genre name="Death Metal" count="27"/><genre name="Decades" count="260"/><genre name="Delta Blues" count="66"/><genre name="Demo" count="515"/><genre name="Dirty South" count="23"/><genre name="Disco" count="227"/><genre name="Doo Wop" count="1"/><genre name="Downtempo" count="61"/><genre name="Dream Pop" count="11"/><genre name="Drum and Bass" count="102"/><genre name="Dub" count="35"/><genre name="Dubstep" count="51"/><genre name="Early Classical" count="4"/><genre name="East Coast Rap" count="5"/><genre name="Easy Listening" count="502"/><genre name="Eclectic" count="109"/><genre name="Educational" count="111"/><genre name="Electric Blues" count="186"/><genre name="Electro" count="770"/><genre name="Electronic" count="972"/><genre name="Emo" count="12"/><genre name="Environmental" count="8"/><genre name="Ethnic Fusion" count="13"/><genre name="European" count="1250"/><genre name="Exotica" count="11"/><genre name="Experimental" count="59"/><genre name="Extreme Metal" count="6"/><genre name="Female" count="1"/><genre name="Filipino" count="12"/><genre name="Flamenco" count="33"/><genre name="Folk" count="532"/><genre name="Folk Rock" count="12"/><genre name="Freestyle" count="77"/><genre name="French" count="8"/><genre name="Funk" count="261"/><genre name="Fusion" count="15"/><genre name="Gangsta Rap" count="115"/><genre name="Garage" count="22"/><genre name="Garage Rock" count="27"/><genre name="German" count="42"/><genre name="Glam" count="30"/><genre name="Gospel" count="2165"/><genre name="Goth" count="46"/><genre name="Government" count="6"/><genre name="Greek" count="237"/><genre name="Grindcore" count="3"/><genre name="Grunge" count="47"/><genre name="Hair Metal" count="0"/><genre name="Halloween" count="16"/><genre name="Hanukkah" count="0"/><genre name="Hard Bop" count="1"/><genre name="Hard House" count="30"/><genre name="Hard Rock" count="225"/><genre name="Hardcore" count="121"/><genre name="Hawaiian and Pacific" count="12"/><genre name="Healing" count="8"/><genre name="Heartache" count="4"/><genre name="Heavy Metal" count="157"/><genre name="Hebrew" count="30"/><genre name="Hindi" count="55"/><genre name="Hip Hop" count="867"/><genre name="Honeymoon" count="1"/><genre name="Honky Tonk" count="12"/><genre name="Hot Country Hits" count="94"/><genre name="House" count="992"/><genre name="IDM" count="2"/><genre name="Idols" count="3"/><genre name="Impressionist" count="2"/><genre name="Indian" count="58"/><genre name="Indie Pop" count="246"/><genre name="Indie Rock" count="51"/><genre name="Industrial" count="56"/><genre name="Inspirational" count="345"/><genre name="Instrumental" count="43"/><genre name="International" count="955"/><genre name="Islamic" count="399"/><genre name="Jam Bands" count="4"/><genre name="Japanese" count="90"/><genre name="Jazz" count="483"/><genre name="JPOP" count="43"/><genre name="JROCK" count="4"/><genre name="Jungle" count="37"/><genre name="Kids" count="93"/><genre name="Klezmer" count="0"/><genre name="Korean" count="2"/><genre name="KPOP" count="39"/><genre name="Kwanzaa" count="1"/><genre name="Latin" count="632"/><genre name="Latin Dance" count="75"/><genre name="Latin Jazz" count="17"/><genre name="Latin Pop" count="247"/><genre name="Latin Rap and Hip Hop" count="7"/><genre name="Latin Rock" count="62"/><genre name="LGBT" count="12"/><genre name="Light Rock" count="75"/><genre name="LoFi" count="2"/><genre name="Lounge" count="218"/><genre name="Love and Romance" count="88"/><genre name="Mariachi" count="30"/><genre name="Meditation" count="25"/><genre name="Mediterranean" count="7"/><genre name="Merengue" count="87"/><genre name="Metal" count="282"/><genre name="Metalcore" count="16"/><genre name="Middle Eastern" count="77"/><genre name="Misc" count="7207"/><genre name="Mixtapes" count="172"/><genre name="Modern" count="20"/><genre name="Modern Rock" count="14"/><genre name="Motown" count="34"/><genre name="Neo Soul" count="22"/><genre name="New Acoustic" count="4"/><genre name="New Age" count="191"/><genre name="New Wave" count="72"/><genre name="News" count="584"/><genre name="Noise Pop" count="3"/><genre name="North American" count="7"/><genre name="Old School" count="27"/><genre name="Old Time" count="15"/><genre name="Old Time Radio" count="53"/><genre name="Oldies" count="861"/><genre name="Opera" count="104"/><genre name="Orchestral Pop" count="1"/><genre name="Original Score" count="18"/><genre name="Other Talk" count="198"/><genre name="Party Mix" count="23"/><genre name="Patriotic" count="3"/><genre name="Piano" count="19"/><genre name="Piano Rock" count="0"/><genre name="Political" count="47"/><genre name="Polka" count="34"/><genre name="Pop" count="14190"/><genre name="Pop Reggae" count="23"/><genre name="Post Punk" count="14"/><genre name="Power Metal" count="2"/><genre name="Power Pop" count="22"/><genre name="Praise and Worship" count="374"/><genre name="Prog Rock" count="96"/><genre name="Progressive" count="35"/><genre name="Progressive Metal" count="12"/><genre name="Psychedelic" count="40"/><genre name="Public Radio" count="1572"/><genre name="Punk" count="98"/><genre name="Quiet Storm" count="4"/><genre name="R&amp;B and Urban" count="493"/><genre name="Ragga" count="8"/><genre name="Rainy Day Mix" count="2"/><genre name="Ranchera" count="8"/><genre name="Rap" count="266"/><genre name="Rap Metal" count="0"/><genre name="Reality" count="3"/><genre name="Reggae" count="296"/><genre name="Reggae Roots" count="34"/><genre name="Reggaeton" count="125"/><genre name="Regional Mexican" count="129"/><genre name="Rock" count="2268"/><genre name="Rock &amp; Roll" count="211"/><genre name="Rock Steady" count="1"/><genre name="Rockabilly" count="66"/><genre name="Romantic" count="95"/><genre name="Russian" count="19"/><genre name="Salsa" count="243"/><genre name="Samba" count="32"/><genre name="Scanner" count="37"/><genre name="Seasonal and Holiday" count="33"/><genre name="Sermons and Services" count="39"/><genre name="Sexy" count="3"/><genre name="Showtunes" count="21"/><genre name="Shuffle" count="11"/><genre name="Singer and Songwriter" count="7"/><genre name="Ska" count="45"/><genre name="Smooth Jazz" count="172"/><genre name="Soca" count="29"/><genre name="Soft Rock" count="533"/><genre name="Soul" count="202"/><genre name="Soundtracks" count="136"/><genre name="South American" count="26"/><genre name="Southern Gospel" count="29"/><genre name="Space Age Pop" count="9"/><genre name="Spiritual" count="462"/><genre name="Spoken Word" count="33"/><genre name="Sports" count="239"/><genre name="Surf" count="8"/><genre name="Swing" count="47"/><genre name="Symphony" count="36"/><genre name="Talk" count="1151"/><genre name="Tamil" count="72"/><genre name="Tango" count="38"/><genre name="Techno" count="330"/><genre name="Technology" count="16"/><genre name="Teen Pop" count="13"/><genre name="Tejano" count="41"/><genre name="Themes" count="15"/><genre name="Thrash Metal" count="15"/><genre name="Top 40" count="1635"/><genre name="Traditional Folk" count="42"/><genre name="Traditional Gospel" count="2"/><genre name="Trance" count="339"/><genre name="Travel Mix" count="8"/><genre name="Tribal" count="9"/><genre name="Tribute" count="0"/><genre name="Trip Hop" count="45"/><genre name="Trippy" count="3"/><genre name="Tropicalia" count="104"/><genre name="Turkish" count="129"/><genre name="Turntablism" count="3"/><genre name="Underground Hip Hop" count="31"/><genre name="Urban Contemporary" count="75"/><genre name="Valentine" count="3"/><genre name="Video Game Music" count="72"/><genre name="Vocal Jazz" count="31"/><genre name="Weather" count="11"/><genre name="Wedding" count="0"/><genre name="West Coast Rap" count="5"/><genre name="Western" count="11"/><genre name="Winter" count="12"/><genre name="Work Mix" count="14"/><genre name="World Folk" count="24"/><genre name="World Fusion" count="2"/><genre name="World Pop" count="132"/><genre name="Worldbeat" count="93"/><genre name="Xtreme" count="1"/><genre name="Zouk" count="94"/></genrelist>

我在没有直接从网址上添加后试了这个。那么是否可以从URL获取xml数据并加载到webix列表中呢?为什么我的xml文件数据没有加载到webix列表中?

1 个答案:

答案 0 :(得分:0)

默认情况下,组件期望传入的XML将具有&#34;项目&#34;每个对象的XML标记。在您的情况下,XML具有&#34;类型&#34;标签。

您可以像下一个

更改XML解析逻辑
webix.DataDriver.myxml = webix.extend({
  records: "//*/genre"
}, webix.DataDriver.xml)

webix.ui({ view:"list", 
      data:xml,
      datatype:"myxml",
      template:"#name# #count#" 
});

第一个代码块添加了新类型的数据 - myxml,它将使用&#34; genre&#34;解析XML。标签。第二个命令使用此新数据类型来加载列表中的数据。

您可以在此处查看工作代码段 - http://webix.com/snippet/bfcc9a89