0

シンプルな「to do リスト」アプリを作成しています。説明付きの項目の表 1 つと、各項目が未完了または完了のいずれかであるステータスの表 1 つ。

私のhtmlテンプレートには次のものがあります。

<h1> To do list </h1><br>
{% if itemlist %}
    {% for desc in itemlist %}
        <li>{{desc}}<select>
                        {% for status in statuslist %}
                        <option value="{{status.id}}">{{status}}</option>
                        {% endfor %}
                        <option selected>{{desc.status}}</option>

                    </select>
        </li>
    {% endfor %}
{% else %}
    <p> No Items Found </p>
{% endif %}

私の問題は、ドロップダウン リストに両方の値を入力し、データベースに保持されている値を自動的に表示することです。私の現在のコードでは、保持されている値は正しく表示されていますが、ドロップダウンで複製されているため、次のいずれかが表示されています。

'incomplete'
'complete'
'incomplete'

また

'incomplete'
'complete'
'complete'

それ以外の

'incomplete'
'complete'

タグに追加しようとしselected="{{desc.status}}"ましたが、各項目に最初の値が入力されます。<option>見たいものを反映するようにこれを変更するにはどうすればよいですか?

4

1 に答える 1

2

次のコードを試してください。

<h1> To do list </h1><br>
{% if itemlist %}
    {% for desc in itemlist %}
        <li>{{desc}}<select>
                        {% for status in statuslist %}
                           {% if status==desc.status %}
                              <option value="{{status.id}}" selected>{{status}}</option>
                           {% else %}
                              <option value="{{status.id}}">{{status}}</option>
                           {% endif %}
                        {% endfor %}
                    </select>
        </li>
    {% endfor %}
{% else %}
    <p> No Items Found </p>
{% endif %}
于 2013-08-30T11:15:59.070 に答える