开发者

Use javascript to generate a templatetag based on events after document ready?

I am working with the new version of django-threadedcomments and making some progress; it integrates nicely with django's commenting system, however, I'm stuck and not sure how to proceed.

For threaded comments to work, the user needs to select a comment to "reply to" and then the correct submit form is brought up (with the appropriate hidden fields) via javascript.

Not using javascript, I would simply use:

{% render_comment_form for [object] with [parent_id] %}

However, I am not sure how I can use this template tag within a javascript function because it will compile/create itself only once; how can I pass it the [开发者_如何学Cparent_id] variable dynacmically via javascript/ajax?


You could do this with Ajax, passing the id of the comment to a dedicated view which just renders the form, but I don't think there's any need. I haven't looked at threaded-comments, but I guess that each comment is of the same object type. Therefore, the only thing that differs in the rendered form would be the id of the comment you're replying to.

So, use the normal template tag render a default form using the first comment on the page, inside a hidden div. Then all your javascript function needs to do is to change the value of the object_pk hidden field within that form, depending on the comment you're replying to. If that id isn't already easily accessible, make it available in the template via the class or id of each comment. Then you can parse it out of there, stuff it into your ready-made form, display it, and you should be good to go.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜