我们如何从QueryString获取一个参数然后将其应用于JSON对象。我有以下JS文件,我想基于查询字符串快速更新dashboard-metrics-target元素。“target” :“sumSeries(SERVER1.metric)”必须使用给定模板在运行时更改为SERVER2.metric。
ex .. http://testdashabord.com/sla-network.incoming.bytes-2013.11.02/logs/test&server=192.168.1.103必须获取“192.168.1.103”
的指标var graphite_url = "demo"; // enter your graphite url, e.g. http://your.graphite.com
var dashboards =
[
{ "name": "Users", // give your dashboard a name (required!)
"refresh": 5000, // each dashboard has its own refresh interval (in ms)
,
"metrics": // metrics is an array of charts on the dashboard
[
{
"alias": "signups", // display name for this metric
"target": "sumSeries(SERVER1.metric)", // enter your graphite barebone target expression here
"description": "New signups to the website", // enter your metric description here
"summary": "sum", // available options: [sum|min|max|avg|last|<function>]
"summary_formatter": d3.format(",f"), // customize your summary format function. see d3 formatting docs for more options
},
{
"alias": "signup breakdown",
"target": "sumSeries(stats.*.event)", // target can use any graphite-supported wildcards
"description": "signup breakdown based on site location",
"renderer": "area", // use any rickshaw-supported renderer
"unstack": true // other parameters like unstack, interpolation, stroke are also available (see rickshaw documentation for more info)
"colspan": 3 // the graph can span across 1,2 or 3 columns
},
]
}, ...
我的方法: ..1。从URL
获取参数var first = getUrlVars()["server"];
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
.. 2。更新数组的元素。
如果建议采用更好的方法,我将感激不尽。
由于