[英]Adding images to a JSon array
I have a JSon array that displays in a JQuery Mobile list.我有一个 JSon 数组,它显示在 JQuery 移动列表中。 It shows the description + price, but I'd like to add a picture Icon to the left.
它显示描述+价格,但我想在左侧添加一个图片图标。
Any pointers on how I could achieve that?关于我如何实现这一目标的任何指示? Can I add an image tag to the "brand"?
我可以为“品牌”添加图像标签吗? Brand is where I'd like the image to display.
品牌是我希望图像显示的地方。
Thanks !谢谢 !
Here's my code.这是我的代码。
// Json array
var productList = {"products": [
{"brand": "brand1", "description": "Product 1", "price": "03.25 "},
{"brand": "brand2", "description": "Product 4", "price": "01.10 "},
{"brand": "brand3", "description": "Product 3", "price": "04.21 "},
{"brand": "brand4", "description": "Product 2", "price": "15.24 "},
{"brand": "brand5", "description": "Product 5", "price": "01.52 "},
{"brand": "brand6", "description": "Product 6", "price": "12.01 "},
{"brand": "brand7", "description": "Product 7", "price": "05.24 "}
] };
// Name Descending
function loadList() {
var list = $("#productList").listview();
var prods = productList.products.sort(function(a, b) {return a.description > b.description;}); $.each(prods, function() { list.append("
" + this.description + " : " + this.price + " ");
});
// CALL SORT BY NAME DESCENDING
$(function(){
$("#sort-list").click(loadList2); });
$(list).listview("refresh");
} }
You're writing out an HTML list derived from a JSON array.您正在写出从 JSON 数组派生的 HTML 列表。 So, one suggestion for achieving what you want:
所以,一个实现你想要的建议:
brand
text you have in there at the moment, you provide the URI for the relevant imagebrand
文本loadList()
function so that you write out an img
tag as part of your HTML, using the URI passed-in from your JSON as that image tag's src
attribute.loadList()
function 以便您写出一个img
标签作为 HTML 的一部分,使用从您的src
作为该图像属性传入的 URI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.