需要 json/jquery 帮助
好吧,我用 jquery 拉入 jsonp feed,然后尝试格式化我的小部件以处理数据。
我已经完成了 90% 的工作,但我不知道如何获取 来获取我的链接中的“item.url”值jsonp。
我知道我缺少 "var url= $('
').attr("href",item.url);"
部分的代码,但我不知道我的生活弄清楚如何让它发挥作用! :(这是我的代码:
gv_responce = function (response) {
// we destroy the script element.
scriptElement.parentNode.removeChild(scriptElement);
//we have all the information in response variable in a json format,
//we just format the results.
for (keyItem in response.posts) {
var item = response.posts[keyItem];
var img = $('<img>').attr('src', item.thumbnail);
var div = $('<div>').append(img);
var title = $('<div>').html($.trim(item.title));
var text = $('<div>').html($.trim(item.excerpt));
var url = $('<div>').attr("href", item.url);
div.append(title);
div.append(text);
div.attr('class', 'gv');
$('#content').append(item.from_user);
$('#content').append(div);
}
}
})();
//当所有内容都加载后,我们调用 api ...
jQuery(document).ready(LKS.makeRequest());
Ok so I'm pulling in a jsonp feed with jquery and then trying to format my widget to work with the data.
I have it 90% working but I can't figure out the how to get a <a href="">
to have the value of my link that is "item.url" in my jsonp.
I know I'm missing some code for the "var url= $('<div>').attr("href",item.url);"
part but I cn't for the life of me figure out how to get it to work! :(
Here is my code:
gv_responce = function (response) {
// we destroy the script element.
scriptElement.parentNode.removeChild(scriptElement);
//we have all the information in response variable in a json format,
//we just format the results.
for (keyItem in response.posts) {
var item = response.posts[keyItem];
var img = $('<img>').attr('src', item.thumbnail);
var div = $('<div>').append(img);
var title = $('<div>').html($.trim(item.title));
var text = $('<div>').html($.trim(item.excerpt));
var url = $('<div>').attr("href", item.url);
div.append(title);
div.append(text);
div.attr('class', 'gv');
$('#content').append(item.from_user);
$('#content').append(div);
}
}
})();
//when everything is loaded we call the api ...
jQuery(document).ready(LKS.makeRequest());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不应该
是
Shouldn't
be
我认为你需要将这一行替换
为
之后,你需要将其添加到你的 DOM 中
I think you need to replace the line
with
afterwards, you'll want to add the to your DOM
你应该在 'a' 标签的 html 中写一些东西。您还创建了“a”标签,但您只是看不到。
试试这个;
而不是
You should write something in 'a' tag's html. You have also created 'a' tag but you just couldn't see.
try this;
instead of