【发布时间】:2018-04-14 04:10:24
【问题描述】:
我还是个新手,但我正在尝试进入 jQuery mobile。
我的应用程序的这一部分(只是为了测试)是基于单击 2 个按钮中的 1 个来加载不同的 twitter 搜索查询。因此,为了更改查询,我正在考虑传递数据标识文本并将其与搜索字符串的其余部分连接起来。
所以我已经开始了,我想我知道我错在哪里,但我不知道如何正确地去做!
基本上我认为出错的是twitter搜索立即加载到页面中,但我的字符串仅在用户单击按钮后才传递(带有类twitterlink)。所以首先我无法让变量传递出去,但其次推文不会加载,因为 url: 在应该的时候没有被填充。
所以当我硬编码 //var url = 'http://search.twitter.com/search.json?q=from:irishhockey';它工作得很好,但目前尝试做任何可变的东西对我不起作用
var twitId;
var url;
$(function(){
//this part is to grab the data-identity string in
$('.twitterlink').live('click',
function() {
twitId = $(this).data("identity");
//this was to concatenate the first part of the string with the twitId (data-identity)
url = 'http://search.twitter.com/search.json?q=from:' + twitId ;
}
);
//with the below hardcoded line uncommented it brings tweets in fine
//var url = 'http://search.twitter.com/search.json?q=from:irishhockey';
$.ajax({
url: url,
dataType: 'jsonp',
success: function(json_results){
console.log(json_results);
// Need to add UL on AJAX call or formatting of userlist is not displayed
$('#twitList').append('<ul data-role="listview"></ul>');
listItems = $('#twitList').find('ul');
$.each(json_results.results, function(key) {
html = '<img src="'+json_results.results[key].profile_image_url+'"/>';
html += '<h3><a href="#">'+json_results.results[key].text+'</a></h3>';
html += '<p>From: '+json_results.results[key].from_user+' Created: '+json_results.results[key].created_at+'</p>';
listItems.append('<li>'+html+'</li>');
});
// Need to refresh list after AJAX call
$('#twitList ul').listview();
}
})
})
我也尝试将其全部放入一键式功能中,希望它不会立即触发 ajax 内容,但这对我也不起作用。
我知道我可能只是以错误的方式处理这个问题,但我只是不确定我应该采取什么方式,所以正如我所说.. 欢迎所有帮助。
【问题讨论】:
标签: jquery android mobile twitter cordova