How to display the particular tag in a file like description in the listview dynamically using jquery?

折月煮酒 提交于 2019-12-24 12:08:11

问题


I'm trying to get the some data from file like some.txt. I want to display some data in that file like description under the each list in the listview.

$(xml).find('section[order="' + order + '"] content').each(function () {
        var content = $(this).text();
        var seq = order + '' + $(this).attr('order');
        var file = $(this).attr('file');
        $("#content").append('<li><a href="#" data-sequence="s' + seq + '" file="' + file + '">' + content + ' </a> </li> ');
    });
    $("#content").listview('refresh');
});

In the above code i created the listview.Now I changed the code as below:

$("#content_list").append('<li><a href="#" file="' + file +'">' + content + ' </a><p class="description text"></p> </li> ');


$(".description").each(function() {
        $(".text").load(file, function() {
                var txt = $(this).find('I').text();
                $("#content_list").append('<p>' + txt + '</p>');

            });
 });

In the above code "file" attribute contains some .txt file. By using this file i want to get some data to display the text as the description for the heading in the list.I tried in many ways but the whole file is displaying.

Thanks in Advance.


回答1:


You started your code .ready which is not recommended to use with jQuery Mobile (explanation) I replaced it with pageinit which is equivalent to .ready but designed to work with jQuery Mobile.

.load wasn't used properly; you needed to read retrieved (data) from the loaded file this way.

$('#files').load(file, function (data) {
 var txt = $(data).find('i').text();
 .......
});

Here is the new code.



来源:https://stackoverflow.com/questions/17040141/how-to-display-the-particular-tag-in-a-file-like-description-in-the-listview-dyn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!