gpt4 book ai didi

ajax - 如何使用来自服务器的JSON数据填充jQuery Mobile ListView ?

转载 作者:行者123 更新时间:2023-12-04 13:17:12 24 4
gpt4 key购买 nike

我正在将jQuery Mobile与PhoneGap结合使用。如何从服务器提取JSON数据并将其填充到 ListView 中。

最佳答案

看看w3schoolsjQuery API上的jQuery.getJSON()方法。

jQuery API的示例:

$.getJSON('ajax/test.json', function(data) {
var items = [];

$.each(data, function(key, val) {
items.push('<li id="' + key + '">' + val + '</li>');
});

$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
});

This example, of course, relies on the structure of the JSON file:

{
"one": "Singular sensation",
"two": "Beady little eyes",
"three": "Little birds pitch by my doorstep"
}

Using this structure, the example loops through the requested data, builds an unordered list, and appends it to the body.

关于ajax - 如何使用来自服务器的JSON数据填充jQuery Mobile ListView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11100531/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com