1

使用 API 我正在使用 Javascript 创建一个论坛。

当用户单击index.html页面上的线程标题时,他们将被带到thread.html此处调用的页面,我正在使用 API 调用来显示 ID 为 1 的线程的结果

var threadRequest = new Request.JSON({
  url: 'control.php?action=getThread&id=1',
  onSuccess: threadSuccess
    }).send();

我的问题是我将如何更改它以便它知道哪个线程已被单击,因此它知道要调用哪个线程,我已经尝试过

function callThread(thread){
  var threadRequest = new Request.JSON({
    url: 'control.php?action=getThread&id='+thread,
    onSuccess: threadSuccess
     }).send();
}

thread是链接到 API 的表中的外键。

线程标题显示如下

var jsonRequest = new Request.JSON({
    url: 'control.php?action=getThreadList',
    onSuccess: ajaxSuccess

}).send();

这也是 threadSuccess 函数

function threadSuccess (jArray){
    jArray.each(function(post){
        var postObject = new PostItem(post.id, post.name, post.comment, post.thread);
        postObject.display().inject($('postList'));
    })
}

我的问题是你明白了吗,这样 url 字符串就会做类似的事情url: 'control.php?action=getThread&id=what ever number thread the user has clicked on

帖子表包含字段 id、名称、评论、时间戳和线程(这将定义帖子将在哪个线程中。)

一个线程表包含 id 和 title。

4

1 回答 1

0

当您输出链接时,请执行以下操作:

<div class="thread" data-id="{{ID from database}}">Thread</div>

document.querySelector('.thread').addEventListener('click', function(e){
    var id = e.currentTarget.getAttribute('data-id');
    callThread(id);
}, false);

你问的问题措辞有点混乱,但如果我试图实现我认为你的目标,这就是我处理它的方式!

于 2013-05-06T21:27:46.210 回答