【问题标题】:I did not show big drill down button我没有显示大的向下钻取按钮
【发布时间】:2018-03-07 05:38:49
【问题描述】:

我没有显示大内容向下钻取按钮。 我加载了json文件,文件的内容变成了向下钻取按钮的内容。但是现在只显示了小内容向下钻取按钮。json就像

{'items': {'---': '---', 
           ‘A’: ‘a’,
            ‘B’: ‘b’,
            ‘C: ‘c’, 
            ‘D’: ‘d’},
 'type1': 
      {
        "---":"---",
        "a1":"a1",
        "a2":"a2",
        "a3":"a3",
        "a4":"a4"
     },
  'type2': 
      {
        "---":"---",
        "b1":"b1",
        "b2":"b2",
        "b3":"b3",
        "b4":"b4"
     },

   'type3': 
      {
        "---":"---",
        "c1":"c1",
        "c2":"c2",
     },

    'type4': 
      {
        "---":"---",
        "d1":"d1",
        "d2":"d2",
        "d3":"d3"
     },
}

views.py 是

from collections import OrderedDict
from django.shortcuts import render
import json
from django.http import JsonResponse

def index(request):
    with open('./data/company_demand.json', 'r') as f:
        json_data = json.loads(f.read(), object_pairs_hook=OrderedDict)

        preprocessed = []
        counter = 0
        for key in ["type1", "type2", "type3", "type4"]:
            values = [(i + counter, value) for i, value in enumerate(json_data[key].values())]
            preprocessed.append((key, values))
            counter = len(json_data[key])
    return render(request, 'index.html', {'json_data': json_data}, {'preprocessed': preprocessed})

index.html 是

    <select id="mainDD" data-placeholder="Choose" class="chzn-select" style="width:600px;">
    {% for i in json_data.items.values %}
            <option>{{ i }}</option>
    {% endfor %}
    </select>
{% for key, values in preprocessed %}
    <select name="type" id="{{ key }}">
    {% for counter, value in values %}
        <option value="{{ counter }}">{{ value }}-{{counter}}</option>
    {% endfor %}
    </select>
{% endfor %}

但是现在这部分

   <select id="mainDD" data-placeholder="Choose" class="chzn-select" style="width:600px;">
    {% for i in json_data.items.values %}
            <option>{{ i }}</option>
    {% endfor %}
    </select>

没有显示。为什么会出现这样的错误?我应该如何解决这个问题?

【问题讨论】:

    标签: javascript jquery python json django


    【解决方案1】:

    json_data 和 preprocessed 应该在传递给模板的同一个字典中。

    改变

    return render(request, 'index.html', {'json_data': json_data}, {'preprocessed': preprocessed})
    

    return render(request, 'index.html', {'json_data': json_data, 'preprocessed': preprocessed})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多