首页 > 解决方案 > 如何使数据库中的标题列表可点击

问题描述

所以我从数据库中提取项目列表,然后将标题显示为列表

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); // 

标签: javascriptnode.jshttp

解决方案


推荐阅读