简体   繁体   English

Django插件中的Javascript问题

[英]Javascript issue in Django plugin

I'm going to use django-threadedcomments library at my Django project. 我将在Django项目中使用django-threadedcomments库。
https://github.com/HonzaKral/django-threadedcomments https://github.com/HonzaKral/django-threadedcomments

The tutorial gives sample code, including Javascript to reply to comments in threaded-comment style. 本教程提供了示例代码,包括Javascript以便以线程评论的方式回复评论。
I've tried to test this sample, and the library works itself but the Javascript to reply to comments doesn't work. 我已经尝试测试此示例,并且该库本身可以运行,但是用于回复评论的Javascript不起作用。
And there's nothing wrong with jQuery loading or with Django static files loading. jQuery加载或Django静态文件加载没有任何问题。

This is the tutorial. 这是本教程。 http://goo.gl/vyFw9 http://goo.gl/vyFw9

I'm wondering: 我很好奇:
1)Is there anything wrong with the script? 1)脚本有什么问题吗?
2)If not, any ideas as to why this doesn't work? 2)如果没有,为什么这不起作用的任何想法?

function show_reply_form(comment_id, url, person_name) {
var comment_reply = $('#' + comment_id);
var to_add = $( new Array(
'<div class="response"><p>Reply to ' + person_name + ':</p>',
'<form method="POST" action="' + url + '">',
'<ul>',  '{{ form.as_ul|oneline }}',
'<li><input type="submit" value="Submit Comment" /></li>',
'</ul>', '</form>', '</div>').join(''));
to_add.css("display", "none");
comment_reply.after(to_add);
to_add.slideDown(function() {
    comment_reply.replaceWith(new Array('<a id="',
    comment_id,'" href="javascript:hide_reply_form(\'',
    comment_id, '\',\'', url, '\',\'', person_name,
    '\')">Stop Replying</a>').join(''));
});
}
function hide_reply_form(comment_id, url, person_name) {
var comment_reply = $('#' + comment_id);
comment_reply.next().slideUp(function (){
    comment_reply.next('.response').remove();
    comment_reply.replaceWith(new Array('<a id="',
    comment_id,'" href="javascript:show_reply_form(\'',
    comment_id, '\',\'', url, '\',\'', person_name,
    '\')">Reply</a>').join(''));
});
}

<a id="c{{ comment.id }}" href="javascript:show_reply_form('c{{ comment.id }}','{% get_free_comment_url post comment %}','{{ comment.name }}')">Reply</a>

First thing I see is that you are not appending to_add to the document at all, ie something like $('#someExistingDiv').append(to_add); 我首先看到的是您根本没有将to_add附加到文档中,即像$('#someExistingDiv').append(to_add);

After creating the to_add , it has to be added to the DOM. 创建to_add ,必须将其添加到DOM中。 I don't think there are any JS errors. 我认为没有JS错误。 I'm pretty sure it you are just not seeing the new comment element created. 我很确定您只是没有看到创建的新comment元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM