json - 如何从导出的谷歌表中的 JSON ULR 获取标题和超链接数据
问题描述
我能够从 G-sheet 获取数据并显示,但我的要求是也显示工作表名称和超链接。工作表名称不应通过搜索过滤它应始终仅显示应过滤的数据
JSON feed UEL 中的超链接单元格数据信息类似于 "gsx$topic":{"$t":"Global Audience Reach Figures"},"gsx$response":{"$t":"Verizon Media Global Product Portfolio Toolkit (内部备忘单)"},"gsx$_cre1l":{"$t":" https://docs.google.com/spreadsheets/d/10tz7wQFG7OIMZgI59SnUF3ER
标题信息存储在 JSON 提要 url 中,如下所示。“标题”:{“类型”:“文本”,“$t”:“数据”}
you can find my sample code below
<div ng-app="sample" ng-controller="sampleController">
<div class="black">
<input type="text" name="search" ng-model="search"
placeholder="search" ng-click="didSelectLanguage()"/>
</div>
<br>
<br>
<br>
<table style="border: 1px solid black ;">
<tbody>
<tr>
<td><center><b>Question</b></center></td>
<td ><center><b>Response</b></center></td>
</tr>
<tr ng-repeat="user in users | filter:searchFilter">
<td style="border: 1px solid black ; width:30%;white-space: pre-wrap;">{{user.gsx$topic.$t}}</td>
<td style="border: 1px solid black ; width:70%;white-space: pre-wrap;">{{user.gsx$response.$t}}</td>
</tr>
</tbody>
</table>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script>
angular.module('sample', []).
controller('sampleController', ['$scope', '$http', function ($scope, $http) {
var url = "https://spreadsheets.google.com/feeds/list/153Obe1TdWlIPyveZoNxEw53rdrghHsiWU9l-WgGwCrE/1/public/values?alt=json";
// var url2 = "https://spreadsheets.google.com/feeds/list/153Obe1TdWlIPyveZoNxEw53rdrghHsiWU9l-WgGwCrE/2/public/values?alt=json";
$http.get(url)
.success(function(data, status, headers, config) {
$scope.users = data.feed.entry;
console.log($scope.users);
})
.error(function(error, status, headers, config) {
console.log(status);
console.log("Error occured");
});
$scope.search='';
$scope.searchFilter=function(item){
if(item.gsx$topic.$t.indexOf($scope.search) != -1 || item.gsx$response.$t.indexOf($scope.search) != -1){
return true;
}
return false;
}
}]);
</script>
解决方案
您的searchFilter()
函数只是gsx$topic.$t
在gsx$response.$t
属性中搜索,因此,现在,您需要在视图中显示 thetitle
和 hiperlink ( link
) 属性。
然后,在您的代码中,使用:
user.link[0].href
显示链接。user.title.$t
显示标题。
像这样的东西:
(function() {
angular.module('sample', []).
controller('sampleController', ['$scope', '$http', function($scope, $http) {
var url = "https://spreadsheets.google.com/feeds/list/153Obe1TdWlIPyveZoNxEw53rdrghHsiWU9l-WgGwCrE/od6/public/values?alt=json";
$http.get(url)
.success(function(data, status, headers, config) {
$scope.users = data.feed.entry;
})
.error(function(error, status, headers, config) {
console.log(status);
console.log("Error occured");
});
$scope.search = '';
$scope.searchFilter = function(item) {
if (item.gsx$topic.$t.indexOf($scope.search) != -1 || item.gsx$response.$t.indexOf($scope.search) != -1) {
return true;
}
return false;
}
}]);
}());
.view,
.view tbody td {
border: #b9b9b9 solid 1px;
}
.view thead th {
border-style: none;
font-weight: bold;
text-align: center;
}
.view tbody td {
white-space: pre-wrap;
}
.view. thead th.title {
width: 10%;
}
.view thead th.question {
width: 20%;
}
.view thead th.response {
width: 70%;
}
<div ng-app="sample" ng-controller="sampleController">
<div class="black">
<input type="text" name="search" ng-model="search" placeholder="search" ng-click="didSelectLanguage()" />
</div>
<br>
<br>
<br>
<table class="view">
<thead>
<tr>
<th class="title">Title</th>
<th class="question">Question</th>
<th class="response">Response</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users | filter:searchFilter">
<td><a href="{{user.link[0].href}}" title="{{user.link[0].href}}">{{user.title.$t}}</a></td>
<td>{{user.gsx$topic.$t}}</td>
<td>{{user.gsx$response.$t}}</td>
</tr>
</tbody>
</table>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
推荐阅读
- php - 显示所有帖子的自定义分类档案
- sql - ERROR SQL Server 只有一个表达式可以在选择列表中指定子查询时没有引入存在
- python - 无法使用 Windows 可执行文件访问 PySpin 系统实例(使用 pyinstaller 创建)
- r - 使用传单生成带有总数的图
- python-3.x - Python 与 DataFrame 聚合合并 ...error: '' 既是索引级别又是列标签,这是不明确的
- reactjs - 通过 react-app-rewired 将 workbox-webpack-plugin 配置添加到 webpack 配置中而不弹出以添加 workbox injectionManifest 插件
- selenium - 自动关闭 Apple id 验证弹出窗口
- php - 带有用户 ID 变量的 MYSQL 的 HTTP 删除请求
- json - 嵌套对象 - 未处理的异常:类型 '_InternalLinkedHashMap
' 不是类型 'Iterable 的子类型 - python - TypeError: write() 只接受一个参数(给定 2 个)python