我正在创建一个Chrome Extension
,利用content-script
在加载完成后将Google Visualisation Table插入到页面中。但问题是该表永远不会显示 - 它也不在html中,如下图所示。
的manifest.json
{
"manifest_version": 2,
"name": "blah",
"version": "1.0",
"permissions": [
"tabs", "http://*/*"
],
"web_accessible_resources": [
"jquery-1.10.2.min.js",
"jquery-1.10.2.min.map"
],
"content_scripts": [
{
"matches": ["http://*.ebay.co.uk/*"],
"js": ["jquery-1.10.2.min.js", "jsapi.js", "myScript.js"],
"run_at": "document_end"
}]
}
MyScript.js
$('#cbrt').after('<div id=\'google_table_div\'></div>');
google.load('visualization', '1', { packages:['table'], callback : function() { drawTable(); } });
function drawTable()
{
alert('draw');
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('number', 'Salary');
data.addColumn('boolean', 'Full Time Employee');
data.addRows([
['Mike', {v: 10000, f: '$10,000'}, true],
['Jim', {v:8000, f: '$8,000'}, false],
['Alice', {v: 12500, f: '$12,500'}, true],
['Bob', {v: 7000, f: '$7,000'}, true]
]);
var table = new google.visualization.Table(document.getElementById('google_table_div'));
table.draw(data, {showRowNumber: true});
}
回调中的alert
永远不会发生。这是最后的HTML:
答案 0 :(得分:0)
您还需要加载'table'包。像这样:
packages:['corechart', 'table']