从JSON对象值中检索URL
Retrieve only URL from JSON object value - Angularjs
我正在访问instagram API,以获取特定用户喜欢的照片和该用户发布的第一条评论。但是,我只想从文本中检索URL,例如,用户tellasaur第一条注释是:
"text":"Check out this link http://www.domain.com",
我只想检索http://www.domain.com。下面是我到目前为止的代码:
所以我想在这个部分应用一个正则表达式{{p.comments.data|getFirstCommentFrom:'tellasaur'}}"
但不确定如何。
JS
angular.module('app',[])
.filter('getFirstCommentFrom',function(){
return function(arr, user){
for(var i=0;i<arr.length;i++)
{
if(arr[i].from.username==user)
return arr[i].text;
}
return '';
}
})
.controller('TestCtrl', function($scope){
$scope.pics = [
{ "images":{
"low_resolution":{
"url":"https:'/'/scontent.cdninstagram.com'/hphotos-xaf1'/t51.2885-15'/s320x320'/e15'/11243658_841091872640638_1858051687_n.jpg",
"width":320,
"height":320
},
},
"comments":{
"count":38,
"data":[
{
"created_time":"1436314585",
"text":"Check out this link http://www.domain.com",
"from":{
"username":"tellasaur",
"profile_picture":"https:'/'/igcdn-photos-b-a.akamaihd.net'/hphotos-ak-xfp1'/t51.2885-19'/11142181_1606991566225969_1204610350_a.jpg",
"id":"174270894",
"full_name":"kristella"
},
"id":"1024203434844916571"
},
{
"created_time":"1436317671",
"text":"Wow",
"from":{
"username":"sbcarol2002",
"profile_picture":"https:'/'/igcdn-photos-b-a.akamaihd.net'/hphotos-ak-xfp1'/t51.2885-19'/10707061_359756607505353_826681437_a.jpg",
"id":"1280059782",
"full_name":"Susan Long"
},
"id":"1024229322726738700"
},
{
"created_time":"1436320519",
"text":"'ud83d'udc93 dreamyy",
"from":{
"username":"veekster",
"profile_picture":"https:'/'/igcdn-photos-h-a.akamaihd.net'/hphotos-ak-xtf1'/t51.2885-19'/11117059_1743047859255223_204225114_a.jpg",
"id":"31179150",
"full_name":"Victoria Wright"
},
"id":"1024253210688915485"
}
]
}
}
]
});
HTML NG-LOOP
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<div ng-app="app" ng-controller="TestCtrl">
<li ng-repeat="p in pics">
<a href="{{p.comments.data|getFirstCommentFrom:'tellasaur'}}" target="_blank"><img ng-src="{{p.images.low_resolution.url}}" /></a>
<p></p>
</li>
</div>
查看如何在文本中正则表达式匹配url的答案,您的解决方案在那里的某个地方
相关文章:
- 存储和检索图像数据URL
- Imgur|检索给定相册链接的直接图像URL
- 用于存储、检索和附加到url的javascript cookie
- 在未命名的json数组url中检索值
- JQuery:从URL检索数据
- Javascript REGEX:需要从嵌入URL中检索ID以及开始和结束时间
- Parse.com-在JavaScript SDK中模板化集合时检索图像URL
- 检索URL中编码的JSON
- 如何使用正则表达式或 jQuery 检索 URL 的最后一部分
- 将图像上传到服务器(picasa/dropbox/etc)并检索url以将其保存在我的数据库中
- 检索URL参数以预先选择多选列表-提线木偶
- node+handlers:动态创建和检索url路径
- 尝试使用jQuery检索URL的一部分;它是有效的,但是字符串是无效的;t返回
- 从函数中检索Url参数
- 如何检索url inAppBrowser当前在
- 在JavaScript中检索URL字符串以生成JSON对象
- 检索url中后跟#的字符串
- 从JSON对象值中检索URL
- 如何在JavaScript中检索URL查询参数
- js:在重定向后检索URL参数