我是Javascript的新手
我被指派使用对象创建数据库并将它们组织成一个数组。我需要确保用户可以看到数组中的所有对象,允许用户添加和删除任何对象,并允许用户搜索任何对象。到目前为止,我有这个,但我很困惑如何在jsfiddle中使用纯粹的javascript在弹出框中显示数组。
var books = [
book1 = {
bookName: "Keeper of the Lost Cities",
author: "Shannon Messenger",
goodreadsRating: "4.5/5"
},
book2 = {
bookName: "Eragon",
author: "Christopher Paolini",
goodreadsRating: "3.9/5"
},
book3 = {
bookName: "The House of the Scorpion",
author: "Nancy Farmer",
goodreadsRating: "4.1/5"
}
];
let array = books;
答案 0 :(得分:0)
您可以使用任何jquery插件来显示弹出框。
<script src="../popupJquery.js"></script>
<div id="contentId" style="display:none">
<script>
$(function(){
$('#contentId').popModal({
html : /*convert your javascript array in html like in table**/
});
});
</script>
答案 1 :(得分:0)
使用以下代码作为参考。
var books = [
book1 = {
bookName: "Keeper of the Lost Cities",
author: "Shannon Messenger",
goodreadsRating: "4.5/5"
},
book2 = {
bookName: "Eragon",
author: "Christopher Paolini",
goodreadsRating: "3.9/5"
},
book3 = {
bookName: "The House of the Scorpion",
author: "Nancy Farmer",
goodreadsRating: "4.1/5"
}
];
var str = "";
books.forEach(function(d){
str += JSON.stringify(d);
});
alert(str);
&#13;