我尝试在我的网络应用程序中集成x-editable
库,以便在页面上创建可编辑的元素
我已按照X-editable
(只是frontEnd
部分)
这是我模板中的代码:
{% block extra_stylesheets %}
<link href="{% static "data_management/plugins/bootstrap/css/bootstrap.min.css" %}" rel="stylesheet" />
<link href="{% static 'data_management/plugins/DataTables/media/css/dataTables.bootstrap.min.css' %}"
rel="stylesheet"/>
<link href="{% static 'data_management/plugins/DataTables/extensions/Responsive/css/responsive.bootstrap.min.css' %}"
rel="stylesheet"/>
<link href="{% static 'data_management/plugins/bootstrap-editable/css/bootstrap-editable.css' %}" rel="stylesheet">
{% endblock %}
{% block extra_head_javascript %}
<script src="{% static "data_management/plugins/jquery/jquery-1.9.1.min.js" %}"></script>
<script src="{% static 'data_management/plugins/bootstrap/js/bootstrap.min.js' %}"></script>
<script src="{% static 'data_management/plugins/bootstrap-editable/js/bootstrap-editable.min.js' %}"></script>
{% endblock%}
{% block content %}
<table class="table table-stripped">
<tr>
<th class="text-center">Visit Identifier</th>
<th class="text-center">Visit Date<br/>
<small style="font-weight: normal;">(Click to change the date)
</small>
</th>
</tr>
{% for course in course.books_set.all %}
<tr>
<td class="text-center">{{ course.name }}</td>
<td class="text-center"><a href="#" id="pub_date" data-type="combodate"
data-value="1984-05-15" data-format="YYYY-MM-DD"
data-viewformat="DD/MM/YYYY"
data-template="D / MMM / YYYY" data-pk="1"
data-title="Select published Date "
class="editable editable-click editable-open"
data-original-title="" title=""
style="background-color: rgba(0, 0, 0, 0);">12/12/2012</a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
我已将此脚本集成到模板的页脚中:
<script>
$(document).ready(function() {
$('#pub_date').editable();
});
</script>
但我不知道为什么这不起作用? 任何帮助都非常感谢
修改
我注意到问题可能是因为id有重复,因为我有一个for loop
且id必须是唯一的!
我该如何避免这种情况?
有没有办法创建一个类并按类调用所有元素?我css
和html
并不是很好。
提前致谢
答案 0 :(得分:0)
我通过以下方式解决了这个问题:
将x-editable
的版本更改为1.5,以适应bootstrap 3
删除id="pub_date"
并按data-name="pub_date"
并放置此脚本:
<script>
$.fn.editable.defaults.mode = 'popup';
$(document).ready(function() {
$('[data-name=pub_date]').editable();
});
</script>
希望它可以帮助别人。