如何做基于AJAX的django无尽分页的django inplace-edit

时间:2014-04-01 21:33:32

标签: javascript ajax django django-endless-pagination django-inplaceedit

基于AJAX的django endless-pagination有2个模板: 1.主要问题_detail.html 2.分页模板issue_detail_page.html

在base.html模板中,就在extra_header块之前,我有:

{% inplace_static %}

我尝试在issue_detail_page.html中执行以下操作:

{% load endless %}
{% load inplace_edit %}

{% lazy_paginate 2 completed_actions using "completed_actions_page" %}
    {% for action in completed_actions %}
        <tr>
            <td><a href="{% url 'action_detail' issuelist.id issue.id action.id %}">{{action.title}}</a></td>
            <td>{% inplace_edit "action.owner" %}</td>
            <td>{% inplace_edit "action.event_date" %}</td>
            <td>{% inplace_edit "action.state" %}</td>
        </tr>
    {% endfor %}
{% show_more %}

但Ajax加载的页面(表数据)不可编辑。

我检查了HTML,发现第一个/原始表数据是:

<span class="inplaceedit textinplaceedit enable">

然后通过单击“更多”链接使用AJAX加载的页面后面的表数据是:

<span class="inplaceedit textinplaceedit">

有人可以建议如何使这项工作?

2 个答案:

答案 0 :(得分:0)

试试这个:

$.getScript("{{ STATIC_URL }}js/jquery.json.js").done(function( script, textStatus ) {
$.getScript("{{ STATIC_URL }}js/jquery.inplaceeditform.js").done(function( script, textStatus ) {
    var options = {"getFieldUrl": "/inplaceeditform/get_field/",
            "saveURL": "/inplaceeditform/save/",
            "successText": "Successfully saved",
            "eventInplaceEdit": "click",
            "disableClick": true,
            "autoSave": true,
            "unsavedChanges": "You have unsaved changes!",
            "enableClass": "enable",
            "fieldTypes": "input, select, textarea",
            "focusWhenEditing": true};
     var inplaceManager = $(".inplaceedit:not(.enable)").inplaceeditform(options);
     inplaceManager.enable();
});
});

答案 1 :(得分:0)

替换文件inplace_js.htmljquery.inplaceeditform.js

  • inplace_js.html

    <!-- it needs jquery to work
    <script src="//code.jquery.com/jquery-2.1.4.js" type="text/javascript"></script>
    -->
    <script src="{{ STATIC_URL }}js/jquery.json.js" type="text/javascript"></script>
    <script src="{{ STATIC_URL }}js/jquery.inplaceeditform.js" type="text/javascript"></script>
    <script type="text/javascript">
        $.inplaceeditform.inplaceManager={}
        $.inplaceeditform.inplaceManager.options = {"getFieldUrl": "{{ inplace_get_field_url }}",
                                                   "saveURL": "{{ inplace_save_url }}",
                                                   "successText": "{{ success_text }}",
                                                   "eventInplaceEdit": "{{ event }}",
                                                   "disableClick": {{ disable_click }},
                                                   "autoSave": {{ auto_save }},
                                                   "unsavedChanges": "{{ unsaved_changes }}",
                                                   "enableClass": "{{ enable_class }}",
                                                   "fieldTypes": "{{ field_types }}",
                                                   "focusWhenEditing": {{ focus_when_editing }}};
    </script>
    <script src="{{ STATIC_URL }}js/jquery.inplaceeditform.hooks.js" type="text/javascript"></script>
    
    {% if activate_inplaceedit %}
        <script type="text/javascript">
            var isIE = function () {
                if(typeof jQuery!== typeof undefined && jQuery.browser === undefined){
                    jQuery.browser = { msie : true};
            }};
        </script>
        <!--[if IE]>
            <script type="text/javascript">
                isIE(); /* IE <= 9*/
            </script>
        <![endif]-->
        <!--[if !IE]><!-->
            <script type="text/javascript"> 
                if (/*@cc_on!@*/false) { 
                    isIE(); /* IE 10*/
                }
            </script>
        <!--<![endif]-->
        <script type="text/javascript">
    
            (function($){
                $(document).ready(function () {
                    {% include "inplaceeditform/inc.extra_options.html" %}
    
                    {% if not toolbar %}
                        $.inplaceeditform.inplaceManager.enable();
                    {% else %}
                        {% include "inplaceeditform/inc.inplace_toolbar.html" %}
                    {% endif %}
    
            });
        })(jQuery);
        </script>
        {% include "inplaceeditform/inc.csrf_token.html" %}
        {{ inplace_js_extra|safe }}
    {% endif %}
    
  • jquery.inplaceeditform.js

    $.extend($.inplaceeditform.inplaceManager, {
        enable: function () {
            $(".inplaceedit").inplaceeditform($.inplaceeditform.inplaceManager.options).enable();
        },
        disable: function () {
            $(".inplaceedit").inplaceeditform($.inplaceeditform.inplaceManager.options).disable();
        }
    });
    

要在任何地方启用inplaceedit,请尝试:     $.inplaceeditform.inplaceManager.enable();