【发布时间】:2021-03-12 15:12:59
【问题描述】:
目前,该页面显示存储在 JSON 字符串中的数组的标题。 我想在按下标题后显示该数组中的其余详细信息。在标题下的另一个列表组中或在新页面上。
这是我目前写的代码:
<div class="list-group" id="mod">
<div class="list-group" id="details">
</div>
</div>
<script>//filling the first list-group #mod
$(document).ready(function(){
$.getJSON('http://localhost:8888/php/json-data-modules.php', function(data) {
$.each(data.modules, function(index, module) {
$('#mod').append('<button type=btn'+module.moduleName+'" class="list-group-item list-group-item-action">'+module.moduleName+'</button>');
});
});
});
//filing the second list-group with new details
$(document).ready(function(){
$("this").on("click", function(){
$.each(data.modules, function(index, module) {
$('#details').append('"class="list-group-item list-group-item-action">'+module.credits+'');
$('#details').append('" class="list-group-item list-group-item-action">'+module.location+'');
});
});
});
这是 JSON 字符串:
{"modules":[{"moduleNo":"999001","moduleName":"Dynamic Web Development","credits":"15","website":"www.dynWeb.ie","dueDate":"2013-05-14","location":"Aungier Street","room":"4037","lat":"53.338545","long":"-6.26607"},{"moduleNo":"999002","moduleName":"Human Computer Interaction","credits":"10","website":"www.hci.ie","dueDate":"2013-04-09","location":"Aungier Street","room":"2005","lat":"53.338545","long":"-6.26607"},{"moduleNo":"999003","moduleName":"Introduction to Programming","credits":"15","website":"www.jscriptIntro.ie","dueDate":"2013-01-11","location":"Kevin Street","room":"1045","lat":"53.337015","long":"-6.267933"},{"moduleNo":"999004","moduleName":"Design Principles","credits":"15","website":"www.designIntro.ie","dueDate":"2013-04-25","location":"Bolton Street","room":"0130","lat":"53.351406","long":"-6.268724"},{"moduleNo":"999005","moduleName":"Design Practice","credits":"10","website":"www.designPract.ie","dueDate":"2013-01-11","location":"Cathal Brugha Street","room":"0123","lat":"53.352044","long":"-6.259514"},{"moduleNo":"999006","moduleName":"Digital Audio","credits":"10","website":"www.dspAudio.com","dueDate":"2013-05-10","location":"Aungier Street","room":"3025","lat":"53.338545","long":"-6.26607"},{"moduleNo":"999007","moduleName":"Digital Signal Processing","credits":"10","website":"www.dspGeneral.ie","dueDate":"2013-04-04","location":"Kevin Street","room":"2103","lat":"53.337015","long":"-6.267933"},{"moduleNo":"999008","moduleName":"History of Digital Media","credits":"5","website":"www.itsbeendone.ie","dueDate":"2013-03-28","location":"Aungier Street","room":"0120","lat":"53.338545","long":"-6.26607"},{"moduleNo":"999009","moduleName":"Digital Asset Management","credits":"5","website":"www.contentStore.ie","dueDate":"2013-05-30","location":"Bolton Street","room":"1004","lat":"53.351406","long":"-6.268724"},{"moduleNo":"999010","moduleName":"Production Skills","credits":"10","website":"www.webDevPro.ie","dueDate":"2013-04-02","location":"Aungier Street","room":"1089","lat":"53.338545","long":"-6.26607"}],"success":1}
【问题讨论】:
-
Err 那不是 PHP,它看起来像 JSON 字符串,但不是 PHP
-
您基本上是在要求我们设计,或者根据规范设计和编写代码。这不是 StackOverflow 的用途,我们互相帮助解决我们遇到的与代码相关的问题,我们不会为您编写代码
-
哦!它在我们得到的一个 php 文件中。在实时服务器上运行
-
您只向我们展示了 JS,仍然没有 PHP 上下文
-
抱歉,我以为是 PHP,因为它在 .php 文件中。我认为第二个 jquery 是如何做我想做的事情,但它不起作用。这就是我寻求帮助的原因。显然,我错了