如何将 true 或 false 的值更改为文本值类型 我正在检查整个 table 中的行 请注意 table 是数据类型 tables?

How do I change the value of true or false to a text value type it I am checking the row in the entire table Note the table is of type datatables?

使用 Django 我正在检查整个 table

中的行,如何将 true 或 false 的值更改为文本值类型
name item type items active
item1 15.0 True
item2 15.0 False

更改值行活动使用 jquery 或 django 文件 view.py:

name item type items active
item1 15.0 displayed
item2 15.0 stope

请帮忙

最优雅的方式可能是为 BooleanField 指定选项,因此:

from django.db import models

<strong>ACTIVE_CHOICES</strong> = [
    (False, 'stope')
  , (True, 'displayed')
  ]

class MyModel(models.Model):
    # …
    active = models.BooleanField(<strong>choices=ACTIVE_CHOICES</strong>)

然后您可以在模板中呈现相应的标签:

{{ mymodelobject<strong>.get_active_display</strong> }}

默认情况下,它还会在 ModelFormModelAdmin 和序列化程序中使用这些选项。

没有代码,很难给出准确的答案。

但在 javascript 中基于布尔值设置值的最简单方法是使用三元运算符。

如果为true,active将设置为“displayed”,如果为false,active将设置为“stope”

活动=boolean_value? “显示”:“采场”