Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 替换HTML表中的值?_Javascript_Jquery_Html_Django_Django Simple History - Fatal编程技术网

Javascript 替换HTML表中的值?

Javascript 替换HTML表中的值?,javascript,jquery,html,django,django-simple-history,Javascript,Jquery,Html,Django,Django Simple History,我正在制作一个HTML表格来显示仓库中已添加、删除和更改的箱子。标题表示方框的所有者、已发生的更改类型以及方框的新内容 我使用Django作为我的后端 我能否将“变更类型”中的值翻译成英语单词,而不是符号~、-和+?我使用Django simple history记录对模型的更改,它返回这些符号。我希望我的表格以“已更改”、“已删除”和“已添加”取代“~”、“-”和“+” 这是view.py: def dashboard(request): box_content_history = B

我正在制作一个HTML表格来显示仓库中已添加、删除和更改的箱子。标题表示方框的所有者、已发生的更改类型以及方框的新内容

我使用Django作为我的后端

我能否将“变更类型”中的值翻译成英语单词,而不是符号~、-和+?我使用Django simple history记录对模型的更改,它返回这些符号。我希望我的表格以“已更改”、“已删除”和“已添加”取代“~”、“-”和“+”

这是view.py:

def dashboard(request):
    box_content_history = Box.history.all().order_by('-history_date')
    return render(request, 'main_app/dashboard.html', {""box_content_history":box_content_history})
HTML:

<table id="asset_changes_datatable">
    <thead>
        <tr>
            <th>Owner</th>
            <th>Type of Change</th>
            <th>Box Contents</th>
        </tr>
   </thead>
   <tbody>
   {% for item in box_content_history %}
        <tr>
            <td>{{ item.project_assigned_to }}</td>
            <td>{{ item.history_type }}</td>
            <td>{{ item.box_contents }}</td>
        </tr>
   {% endfor %}
   </tbody>
</table>

正如在注释中已经提到的,只需在模板中将{{item.history_type}}更改为{{{item.get_history_type_display}}

这是什么魔法?它来自哪里? 这实际上是普通的django功能,并在中进行了解释

对于已设置的每个字段,对象将有一个get\u FOO\u display方法,其中FOO是字段的名称。此方法返回字段的“人类可读”值

为什么它适用于django simple history的history_类型字段? 非常简单:history_type字段设置了上述选项。我通过查看github上的代码检查了这一点


编辑以更正术语顺序扫描是否显示负责呈现~/-/+符号的视图/模板代码?我刚刚完成了此操作,请尝试将{{item.history\u type}更改为{{item.get\u history\u type\u display}是否符合您的目标。如果有,我会提供一个更彻底的答案来解释它。它确实有效!非常感谢。太棒了!这是简单历史中的某种内置方法吗?太棒了。在模型中定义了这些人类可读的值,这非常有用!谢谢你的回答!
"history_type": models.CharField(
    max_length=1,
    choices=(("+", _("Created")), ("~", _("Changed")), ("-", _("Deleted"))),
),