Javascript 如何将数据添加到Google表格图表中
我想用谷歌图表构建一个表格,其中包含关于团队的信息、团队中的人员以及他们在团队中的角色。 我遇到的一个问题是,数据库中的某些字段为空,但仍应将其添加到表中的同一行 我希望它看起来像这样的一个例子:Javascript 如何将数据添加到Google表格图表中,javascript,for-loop,datatable,google-visualization,Javascript,For Loop,Datatable,Google Visualization,我想用谷歌图表构建一个表格,其中包含关于团队的信息、团队中的人员以及他们在团队中的角色。 我遇到的一个问题是,数据库中的某些字段为空,但仍应将其添加到表中的同一行 我希望它看起来像这样的一个例子: TeamName Members Role Contract Country City Joe Doe Programmer Own Staff Greenland Nuuk Jane Doe Design
TeamName Members Role Contract Country City
Joe Doe Programmer Own Staff Greenland Nuuk
Jane Doe Design
到目前为止,我已经构建了这个,但问题是数据库中只有一个对象具有所有信息,因此只有那个人被添加到表中
function drawChart() {
// Table-chart with the teams
var data = new google.visualization.DataTable();
data.addColumn('string', 'TeamName');+
data.addColumn('string', 'Members');
data.addColumn('string', 'Role');
data.addColumn('string', 'Contract');
data.addColumn('string', 'Country');
data.addColumn('string', 'City');
_teams = []
_object = []
{% for obj in object_list %}
{% for team in obj.team.items %}
{% for role in obj.role.items %}
{% for contract in obj.cont.items %}
{% for location in obj.loc.items %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
google.visualization.Table(document.getElementById('table-div'));
table.draw(data, {showRowNumber: true, width: '100%', height: '100%'});
}
有人知道我该如何解决这个问题吗?请分享
for
循环中的代码好吗?你在哪里使用addRow
?@WhiteHat我已经删除了该代码,因为它没有按预期工作,希望我们能找到另一种方法来实现这一点,而不用使用太多的循环扫描。不知怎的,你共享了-->object\u list