CSS / HTML / PHP显示交替数组列表(谷歌Chrome扩展) [英] CSS / HTML / PHP Displaying List of Alternating Arrays (Google Chrome Extension)
问题描述
我试图创建一个谷歌的Chrome扩展在几个不同的阵列(姓名,年龄,地区等)传递给popup.html和他们使用的是类似于HTML / CSS / PHP的东西显示:
I'm trying to create a google chrome extension in which several different arrays (Name, Age, Country etc.) are passed to the popup.html and they are displayed using HTML / CSS / PHP something similar to:
李四                28
美国
保罗·史密斯              58
日本
罗伯特·格林          39
德国
John Doe 28
America
Paul Smith 58
Japan
Robert Green 39
Germany
我能够通过每个阵列popup.html惟独显示传递的最后阵列 - 我一直没能找到一种方法来显示交替阵列的每个条目。
I'm able to pass each array to popup.html except only the last array passed is displayed - I haven't been able to find a way to display each entry of alternating arrays.
在这一点上我很困惑,我的方法应该是什么。我应该使用列表,或改变阵列传递到HTML文件或有显示交替阵列的简单方法的方式吗?
At this point I'm confused as to what my approach should be. Should I be using lists, or changing the way the arrays are passed to the HTML file or is there a simple way to display alternating arrays?
任何帮助将大大AP preciated!谢谢!
Any help would be greatly appreciated! Thank you!
请注意:
名称= ['李四','保罗·史密斯,罗伯特格林']
年龄= [28,58,39]
国家='美','日本','德国']
Name = ['John Doe', 'Paul Smith', 'Robert Green']
Age = [28, 58, 39]
Country = ['America', 'Japan', 'Germany']
编辑 - 请参考样本code更新时间:
EDIT - UPDATED WITH SAMPLE CODE
('味精'是传递到popup.js从background.js演示单个阵列)
('msg' is a single array for demonstration purposes passed into popup.js from background.js)
popup.js:
var port = chrome.extension.connect({name: "Sample Communication"});
port.onMessage.addListener(function(msg) {
document.getElementById('status').textContent = msg;
});
popup.html:
popup.html:
<html>
<head>
<script src="popup.js"></script>
<style type="text/css" media="screen">
body {
min-width : 400px;
min-height : 300px;
text-align : right;
background-color: #D0D0D0; }
#status {
font-size : 10px;
color : #0000CC;
text-align : left;
font-family : "Times New Roman", Times, serif; }
</style>
</head>
<body>
<div id="status"></div>
</body>
</html>
运行这只是显示在一个逗号分隔段阵列。从更多的研究似乎使用PHP可能实现一个表最简单的方法;但是,我仍然不能确定是否可以给数组传递到表中。
Running this simply displays the array in a comma-separated paragraph. From more research it seems that using PHP might be the easiest way to implement a table; however, I'm still unsure whether it is possible to pass the array into the table.
推荐答案
您只是每次收到一个新的数据的时候覆盖显示器:
You are simply overwriting your display each time you receive a new piece of data:
port.onMessage.addListener(function(msg) {
// This wipes the old value:
document.getElementById('status').textContent = msg;
});
您需要的将是追加数据,或更好,但通过所有数据的一次,它的格式正确,然后输出到页面。
You'll need to either append data, or better yet pass all of the data at once, format it properly, and then output it to the page.
这真的很难做到的答复更详细的,因为:1)你好像不很清楚自己在做什么,2)有在问题没有precise规格
It's really hard to be more detailed with the answer since: 1) you don't seem to know very well what you're doing, 2) there are no precise specifications in the question.
您应该多练习了一下自己,看看了一些教程,否则,帮助您不会真的对你有所帮助,或给他人。然后,如果你仍然有问题(可能不是扩展专用),它们分割成块和后在这里。 本指南帮助。
You should practice a bit more on your own and look up a few tutorials, otherwise helping you won't really be helpful to you, or to others. Then, if you still have questions (probably not extension-specific), split them into chunks and post here. This guide helps.
这篇关于CSS / HTML / PHP显示交替数组列表(谷歌Chrome扩展)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!