我将列表[object1, object2, ...]
传递到下拉菜单。当我按下F12
时,希望在以下HTML代码中知道object1
的{{1}}的ID。我想在JS文件中使用该id。我怎样才能为列表中的每个项生成一个id。否则,我可以在JS文件中使用什么而不是Total number of clients
的ID号?
Total number of clients

以下是我生成下拉菜单的方法:
<div class="select-wrapper select initialized"><span class="caret">▼</span><input type="text" class="select-dropdown" readonly="true" data-activates="select-options-655bff26-fb5b-1642-ddeb-41bd1b4ab105" value="Total number of clients">
<ul id="select-options-655bff26-fb5b-1642-ddeb-41bd1b4ab105" class="dropdown-content select-dropdown" style="width: 100px; position: absolute; top: 1px; left: 0px; opacity: 1; display: none;">
<li class="active selected"><span>Total number of clients</span></li>
<li class=""><span>Total new loans</span></li>
<li class=""><span>Total renewals</span></li>
<li class=""><span>Total debit fees</span></li>
<li class=""><span>Total brokerage fees</span></li>
<li class=""><span>Total interest</span></li>
<li class=""><span>Total accounts receivable</span></li>
<li class=""><span>Total active accounts receivable</span></li>
<li class=""><span>Total special accounts receivable</span></li>
<li class=""><span>Total accounts loss</span></li>
<li class=""><span>Total completed loans</span></li>
<li class=""><span>Total terminated loans</span></li>
<li class=""><span>Total suspended loans</span></li>
<li class=""><span>Total delayed fees</span></li>
<li class=""><span>Total denied fees</span></li>
</ul>
<select class="select initialized" id="id_type_choice" name="type_choice">
<option value="0" selected="selected">Total number of clients</option>
<option value="1">Total new loans</option>
<option value="2">Total renewals</option>
<option value="3">Total debit fees</option>
<option value="4">Total brokerage fees</option>
<option value="5">Total interest</option>
<option value="6">Total accounts receivable</option>
<option value="7">Total active accounts receivable</option>
<option value="8">Total special accounts receivable</option>
<option value="9">Total accounts loss</option>
<option value="10">Total completed loans</option>
<option value="11">Total terminated loans</option>
<option value="12">Total suspended loans</option>
<option value="13">Total delayed fees</option>
<option value="14">Total denied fees</option>
</select>
</div>
STATISTICS_TYPE_CHOICES = (
(0, _('Total number of clients')),
(1, _('Total new loans')),
(2, _('Total renewals')),
(3, _('Total debit fees')),
(4, _('Total brokerage fees')),
(5, _('Total interest')),
(6, _('Total accounts receivable')),
(7, _('Total active accounts receivable')),
(8, _('Total special accounts receivable')),
(9, _('Total accounts loss')),
(10, _('Total completed loans')),
(11, _('Total terminated loans')),
(12, _('Total suspended loans')),
(13, _('Total delayed fees')),
(14, _('Total denied fees')),
)
class StatisticsBaseForm(forms.Form):
type_choice = forms.ChoiceField(label=_("Type"), choices=settings.STATISTICS_TYPE_CHOICES, initial=0, required=False)
period = forms.ChoiceField(label="Period", choices=settings.PERIODS, initial='week', required=False)
from_regular_product = forms.ModelChoiceField(
queryset=ProductConfig.objects.filter(pk=-1), required=False,
label=_('Product'))
from_special_product = forms.ModelChoiceField(
queryset=ProductConfig.objects.filter(pk=-1), required=False,
label=_('Product'))
product_type = forms.ChoiceField(
choices=settings.LOANWOLF_PRODUCT_TYPE_CHOICES, required=False,
initial='regular', label=_('Product type'))
debit_frequency = forms.ChoiceField(
choices=settings.LOANWOLF_PRODUCT_DEBIT_FREQUENCIES_CHOICES,
required=False)
def __init__(self, *args, **kwargs):
super(StatisticsBaseForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_class = 'row'
self.helper.layout = StatisticalToolsLayout
company = get_current_company()
regular_products = company.available_products.filter(
is_active=True, product_type='regular')
special_products = company.available_products.filter(
is_active=True, product_type='special')
self.fields['from_regular_product'].queryset = regular_products
self.fields['from_special_product'].queryset = special_products
if regular_products:
self.fields['from_regular_product'].initial = \
settings.LOANWOLF_EXTERNAL_REQUEST_DEFAULT_PRODUCT_INDEX
if special_products:
self.fields['from_special_product'].initial = \
settings.LOANWOLF_EXTERNAL_REQUEST_DEFAULT_PRODUCT_INDEX
class Meta:
model = Statistics
fields = '__all__'
StatisticalToolsLayout = \
CardContent(
Row(
Column('type_choice', css_class="s2"),
),
Row(
Column('period', css_class="s2"),
Column('product_type', css_class="s2"),
Column(
'from_regular_product',
'from_special_product',
css_class="s4"),
Column('debit_frequency', css_class="s2"),
),
CardAction(
Div(
Button('apply', _('Apply'), css_class='waves-effect waves-light btn white-text'),
css_class="right-align"),
),
)
我在下拉菜单<div class="row main-content">
<div class="col s10">
<div class="card">
<h5>{{ form.form_title }}</h5>
{% crispy form form.helper %}
</div>
</div>
</div>
中有不同类型的可能请求。例如,如果Type
,则会隐藏其他一些下拉菜单,而其他菜单将会显示。但是,我需要一个id号来做这样的事情(http://jsfiddle.net/jadendreamer/5SArB/)。我是否需要为Total number of loan is selected
中的所有项目生成ID?
如果遗漏了某些内容,请告诉我。
问题很简单......如果知道STATISTICS_TYPE_CHOICES
给我们一个下拉菜单并且在JS文件中使用了ids,我怎么能为STATISTICS_TYPE_CHOICES中的每个元素生成一个id号?
type_choice = forms.ChoiceField(label=_("Type"), choices=settings.STATISTICS_TYPE_CHOICES, initial=0, required=False)
答案 0 :(得分:1)
如果你打算使用javascript,大概你会有jquery,你只能选择你没有隐藏的项目。
我假设您要使用某些值隐藏某些选项,您可以隐藏它们:
$('#id_type_choice option[value="10"]').hide();
您可以根据自己的喜好获得具体内容,例如父母的身份证明。然后,您可以计算所有未隐藏的选项。
var optCount = $('#id_type_choice option:visible').length