Jquery Mobile获取xml文件的第一个值

时间:2014-07-31 17:28:30

标签: jquery ajax xml jquery-mobile

我似乎对Jquery Mobile有一个非常基本的问题。我有以下XML代码:

<projects>
    <project>
        <pTitle>2</pTitle>
        <pDescription>Un project test 2</pDescription>
        <pPicture>img/icon/bin_opened.png</pPicture>
        <pModel>Modèle de project 2</pModel>
        <pInfo1>project 2 - Info 1</pInfo1>
        <pInfo2>project 2 - Info 2</pInfo2>
    </project>
    <project>
        <pTitle>3</pTitle>
        <pDescription>Un project test 3</pDescription>
        <pPicture>img/icon/file.png</pPicture>
        <pModel>Modèle de project 3</pModel>
        <pInfo1>project 3 - Info 1</pInfo1>
        <pInfo2>project 3 - Info 2</pInfo2>
    </project>
    <project>
        <pTitle>project 4</pTitle>
        <pDescription>Un project test 4</pDescription>
        <pPicture>img/icon/network.png</pPicture>
        <pModel>Modèle de project 4</pModel>
        <pInfo1>project 4 - Info 1</pInfo1>
        <pInfo2>project 4 - Info 2</pInfo2>
    </project>
</projects>

基本上,我想获得项目图片的价值。我使用以下JS脚本:

$(document).on('pagebeforeshow', '#projets', function()
    {
        $.ajax(
        {
            type: "GET",
            url: "projects.xml",
            dataType: "xml",
            success: function(xml)
            {
                var html = "";
                html += "<div class='ui-grid-b'>";
                html += "<div class='ui-block-a' id='block_a'>"
                html += "<ul data-role='listview' data-split-icon='star' data-split-theme='a' class='listview' id='daViewList'>"

                $(xml).find("project").each(function()
                {
                    html += "<li id='grid_li'>"
                    html += "<a href='simulations.html'>";
                    html += "<img id='project_thumbnail' src='http://demos.jquerymobile.com/1.2.0-alpha.1/docs/lists/images/album-bb.jpg' />";
                    html += "<h3 class='noWrap'>" + $(this).find('pTitle').text() + "</h3>";
                    html += "<p class='noWrap'>" + $(this).find('pModel').text() + "</p>";
                    html += "<p class='noWrap'>" + $(this).find('pDescription').text() + "</p></a>";

                    html += "<a href='simulations.html' data-transition='slide' data-icon='arrow-r' data-theme='c'></a>";
                    html += "</li>";
                });

                html += "</ul>";
                html += "</div>";
                html += "</div>";
                $(html).appendTo('#liste');
                $("#project_thumbnail").attr('src', $(xml).find("project").find('pModel').text());
                $("#daViewList").listview().listview("refresh");

                alert($(xml).find("project").find('pPicture').text());
            }
        });
    });

当我尝试使用行

处的XML值更改img src时,此代码不起作用
 $("#project_thumbnail").attr('src', $(xml).find("project").find('pModel').text());
                    $("#daViewList").listview().listview("refresh");

通过警报,我看到此命令返回所有图片的连接值(即img / icon / bin_opened.pngimg / icon / file.pngimg / icon / network.png)。

alert($(xml).find("project").find('pPicture').text());

由于它处于循环中,我想通过good节点的XML值更改所有img src。我怎么能这样做?

0 个答案:

没有答案