gpt4 book ai didi

javascript - 如何从 Angularjs 中的选择选项生成的动态 url 中删除双引号?

转载 作者:行者123 更新时间:2023-12-03 09:23:51 25 4
gpt4 key购买 nike

我想创建 url,它将从服务器获取 json 数据。我能够生成动态网址,但它包含双引号http://localhost/admin/metering/samples?meter="instance"&group_by="project"&stats_attr="avg"&date_options=7&date_from=&date_to=

请参阅上面的网址,它包含双引号中的“实例”,但它不应该是这样的,
正确的网址是 http://192.168.206.133:8080/admin/metering/samples?meter=instance&group_by=project&stats_attr=avg&date_options=7&date_from=&date_to=

注意:如果您知道生成动态网址的好方法,那么您可以告诉我。

工作演示 http://plnkr.co/edit/Ygkqlf60SLaLTtBaUoJf?p=preview

Angularjs

 $http.get("data.json")
.success(function(response) {
$scope.metrics = response.nova_meters.concat(response.glance_meters);

$scope.metric = $scope.metrics[0];
$scope.groups=[{"name": "project", "value":"project" ,"label": "project"}];
$scope.group_by = $scope.groups[0];
$scope.stats_attrs=[
{
"name": "avg",
"value": "avg",
"label": "avg"
},
{
"name": "min",
"value": "min",
"label": "min"
},
{
"name": "max",
"value": "max",
"label": "max"
},
{
"name": "sum",
"value": "sum",
"label": "sum"
}
];

$scope.stats_attr = $scope.stats_attrs[0];
$scope.date_options = [{
"value": 1,
"label": "Last day"
}, {
"value": 7,
"label": "Last week"
}, {
"value": 23,
"label": "Month to date"
}, {
"value": 30,
"label": "Last 30 days"
}, {
"value": 356,
"label": "Last year"
}, {
"value": "Other",
"label": "Other"
}];

$scope.date_option = $scope.date_options[1];
var url="http://192.168.206.133:8080/admin/metering/samples?"+"meter="+JSON.stringify($scope.metric.label)+"&group_by="+JSON.stringify($scope.group_by.label)+"&stats_attr="+JSON.stringify($scope.stats_attr.label)+"&date_options="+JSON.stringify($scope.date_option.value)+"&date_from=&date_to=";

});

最佳答案

从 URL 中删除 JSON.stringify

var url="http://192.168.206.133:8080/admin/metering/samples?"+"meter="+$scope.metric.label+"&group_by="+$scope.group_by.label+"&stats_attr="+$scope.stats_attr.label+"&date_options="+$scope.date_option.value+"&date_from=&date_to=";

http://plnkr.co/edit/uvqwbBttzPRXgIQLOEOL?p=preview

关于javascript - 如何从 Angularjs 中的选择选项生成的动态 url 中删除双引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31747048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com