【发布时间】:2023-09-15 00:35:01
【问题描述】:
我在动态搜索表单上显示结果时遇到问题。 jquery的代码是:
$("#searchterm").keyup(function (e) {
if (this.value.length > 4) {
var q = $("#searchterm").val();
$('#output').text('You typed ' + $(this).val() + '.');
$.getJSON('http://catalog.api.2gis.ru/search?what=' + q + '&where=москва&version=1.3&key=rujrdp3400&pagesize=50&callback=?',
function (data) {
var tmp = {};
if (data !== undefined && data.result.length !== 0) {
$.each(json.result,function(i,result) {
var type = result.id;
if (!tmp[type]) {
tmp[type] = [];
}
tmp[type].push(result);
alert(result.id);
});
var html = [];
$.each(tmp, function (key, item) {
html.push('<div id=' + key + '><h3 id=' + key + '>' + key + '</h3> <span>');
html.push(result.length + '</span><ul id="items">');
$.each(result, function (i, val) {
var isLiked = getItemIdxByIdFromStorage(val.id) != -1;
html.push('<li><a href="#" onClick="podcat('+"'"+val.id+"'"+')">'+val.name+'</a></li>');
});
html.push('</ul></div>');
});
$('#results').html(html.join(''));
$('h3#listings').replaceWith('<h3>Total results: </h3>');
} else {
$('#results').html('Nothing found');
}
});
} else {
$('#results').html('Please type at least 5 characters');
}
});
我正在尝试获取 result.id 和 result.name...请在搜索字段中输入 Pizza。
如果有人可以帮助我,我将不胜感激。抱歉,我的 jquery 水平比初学者还低。
也请使用我的小提琴http://jsfiddle.net/TCYyH/
【问题讨论】: