有一个products.json文件
[
{
"id": 1,
"name": "stul"
}
{
"id": 2,
"name": "stol"
}
]
这是布局
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div class="product-container">
<div class="product">
<div class="id"></div>
<div class="name"></div>
</div>
</div>
</body>
</html>
inproduct-container
应该插入product
,但是其中可能有很多如何使用jquery将所有产品解析为 html或者如果有 1000 个产品基本上是个坏主意?
它可以是这样的:
对于解析
JSON
:也许您不需要一次加载所有内容,您可以将其划分为页面或加载某些用户操作的部分(
Lazy Loading
)。如果你得到 JSON,不要解析。