javascript - 如何使数据库中的标题列表可点击
问题描述
所以我从数据库中提取项目列表,然后将标题显示为列表
global.screens.menu.search = function() {
var searchData = document.getElementById('search-input').value;
global.method.request('search-item', {title: searchData}, function(err, res) {// if() error handling logic}
// show new list of items.
else {
var list = document.createElement('ul');
for (var i = 0; i < res.list.length; i++) {
var item = document.createElement('li');
item.setAttribute('id', 'search-list-' + res.list[i].id);
item.appendChild(document.createTextNode(res.list[i].title));
list.appendChild(item);
}
document.getElementById('list').appendChild(list);
}
})
};
这创建了一个看起来像的项目列表
<li id="search-list-12">the first book</li>
<li id="search-list-16">the fourth book</li>
我要做的是使这些项目中的每一个都可点击(超链接)到一个名为 product-page.html 的新页面并传递书籍 ID,以便我可以通过 ID 在产品页面中显示书籍。
我正在考虑将会话变量设置为书籍 ID,然后将 href 设置为“localhost://product-page”,然后在重定向页面加载填充页面,然后删除会话变量。不确定这是否是正确的方法。
在我的 product-page.html 中,我有一个将填充所有内容的函数调用。我只需要向它传递该项目的 ID。
global.screens.product.activate(id); //
解决方案
推荐阅读
- c# - 如何通过 Selenium 和 C# 查找动态元素并发送文本
- postgresql - 为什么我的只读 Postgresql 用户被拒绝对表的读取权限?
- c# - 将接口作为参数而不是特定类型传递
- crystal-lang - Crystal:如何增加实例化后数组可以容纳的类型数量
- .net - Visual Studio Community 2017 版本 15.9.2 无法从 Microsoft 符号服务器加载符号
- javascript - 将 Vue 道具的默认设置为父选项
- symfony - Doctrine/Symfony:如何管理 2 个数据库中的实体?
- spinnaker - 触发大三角帆管道
- javascript - JavaScript 小部件必须等待 AngularJS 变量值
- javascript - 如何禁用 ng-map 上的卫星和地形选项?