如何控制json条目时获取它
how to control json entries when fetch it
我的代码显示所有json文件条目的图像和标题和摘要所有我需要显示的图像,标题和摘要到第一个条目,并将显示标题到其他条目。
请建议。
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function() {
var entries = [];
var dmJSON = "http://localhost:8080/Newfolder/test.json";
$.getJSON( dmJSON, function(data) {
$.each(data.entries, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.image + "</td>" + "<td>" + f.title + "</td>" + "<td>" + f.summary + "</td>" + "</tr>"
$(tblRow).appendTo("#entrydata tbody");
});
});
});
</script>
</head>
<body>
<div class="wrapper">
<div class="profile">
<table id= "entrydata" border="1">
<thead>
<th>ID</th>
<th>UserName</th>
<th>Message</th>
<th>Location</th>
<th>Time</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>
请注意我更新的代码:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function() {
var items = [];
var dmJSON = "http://localhost:8080/Newfolder/realaljazeera.json";
$.getJSON( dmJSON, function(data) {
$.each(data.entries, function(i, f) {
if (i == 0) {
var tblRow = "<tr>" + "<td>" + "<img src="+f.Image3+"/>" + "</td>" + "<td>" + f.Title + "</td>" + "<td>" + f.Summary + "</td>" + "</tr>"
} else {
var tblRow = "<tr>" + "<td>" + f.Title + "</td>" + "</tr>"
}
$(tblRow).appendTo("#entrydata tbody");
});
});
});
</script>
</head>
<body>
<div class="wrapper">
<div class="profile">
<table id= "entrydata" border="2" style="width:680px;">
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>
$.each(data.entries, function(i, f) {
if (i == 0) {
var tblRow = // what you want for first entry
} else {
var tblRow = // what you want for other entries
}
$(tblRow).appendTo("#entrydata tbody");
});
相关文章:
- 如何使用 Node JS 获取 JSON 嵌套数组值
- 使用Javascript/JQuery获取JSON GET数据
- 在jQuery中获取JSON
- 如何使用jQuery按键搜索和获取json行数据
- 如何使用jquery获取Json的节点
- 通过字符串获取JSON对象
- 通过Azure存储以HTML形式获取JSON文件
- 获取JSON并使用Javascript解析为字符串
- 如何在angular中获取json对象的名称
- 如何使用angular获取json对象的名称
- 如何使用Ajax JQuery.ech()获取JSON值
- 可以't通过从googlemapapi获取json值
- 获取json结果的身份验证问题
- Javascript:获取 JSON 中的值计数
- 按服务获取JSON数据
- 如何使用javascript获取json元素
- 从javascript文件中获取JSON,并使用NodeJS在路由文件中显示
- 如何从给定的代码中获取JSON对象
- 获取 JSON 数据将数组项添加到变量
- 如何从具有动态可观察属性的淘汰对象中获取 JSON 字符串