Динамическая установка состояний радиокнопок с помощью CFLOOP
Я использую cfloop
динамически создавать / заполнять три набора полей ввода, а также некоторые переключатели, которые используются для рейтинговой системы. Поля ввода работают как положено. Однако у меня проблемы с переключателями.
По какой-то причине (и я предполагаю, что это простая причина) переключатели не отражают значения, отправленные им. Например: скажем, у меня есть 3 вещи, которые я оцениваю. Если зацикленные значения 5,4,3
все переключатели отображаются так, как если бы передаваемое им значение было 5
, Это похоже на то, как если бы все наборы полей создавались первыми и все принимали первое значение (например, проверялись), а не создавали первый набор полей, вставляли значение, а затем создавали второй набор полей и т. Д. (Как я предположил бы в цикле). Опять же, это работает для всего, кроме кнопок радио. Любое понимание будет с благодарностью.
Вот мой код:
<cfloop query="postedBy" startrow="1" endrow="4">
<cfquery name="score" datasource="myDB">
SELECT Round(sum(leadership)/Count(leadership)) as leadership
, Round(sum(communication)/Count(communication)) as communication
, Round(sum(fairness)/Count(fairness)) as fairness
, Round(sum(ethics)/Count(ethics)) as ethics
, Round(sum(competence)/Count(competence)) as competence
FROM score_base
WHERE score_ID = '#postedBy.score_id#'
</cfquery>
<cfset score_ID=#postedBy.score_id#>
<cfoutput>id: #postedBy.score_id#</cfoutput>
<cfoutput>My score: #score.leadership#, #score.communication#, #score.fairness#, #score.ethics#, #score.competence#</cfoutput>
<cfset counter = counter+1>
<cfset "currentScore#score.leadership#" = "checked">
<cfset "currentScoreb#score.communication#" = "checked">
<cfset "currentScorec#score.fairness#" = "checked">
<cfset "currentScored#score.ethics#" = "checked">
<cfset "currentScoree#score.competence#" = "checked">
...
<div class="rating-wrapper">
<cfform>
<label>Leadership</label>
<cfinput type="radio" class="star" name="leadership" value="1" disabled="disabled" checked = '#currentScore1#'/>
<cfinput type="radio" class="star" name="leadership" value="2" disabled="disabled" checked = '#currentScore2#'/>
<cfinput type="radio" class="star" name="leadership" value="3" disabled="disabled" checked = '#currentScore3#'/>
<cfinput type="radio" class="star" name="leadership" value="4" disabled="disabled" checked = '#currentScore4#'/>
<cfinput type="radio" class="star" name="leadership" value="4" disabled="disabled" checked = '#currentScore5#'/>
</cfform>
</div><!-- END div class="rating-wrapper" -->
<div class="rating-wrapper">
<cfform>
<label>Communication</label>
<cfinput type="radio" class="star" name="communication" value="1" disabled="disabled" checked = '#currentScoreb1#'/>
<cfinput type="radio" class="star" name="communication" value="2" disabled="disabled" checked = '#currentScoreb2#'/>
<cfinput type="radio" class="star" name="communication" value="3" disabled="disabled" checked = '#currentScoreb3#'/>
<cfinput type="radio" class="star" name="communication" value="4" disabled="disabled" checked = '#currentScoreb4#'/>
<cfinput type="radio" class="star" name="communication" value="5" disabled="disabled" checked = '#currentScoreb5#'/>
</cfform>
</div><!-- END div class="rating-wrapper" -->
<div class="rating-wrapper">
<cfform>
<label>Fairness</label>
<cfinput type="radio" class="star" name="fairness" value="1" disabled="disabled" checked = '#currentScorec1#'/>
<cfinput type="radio" class="star" name="fairness" value="2" disabled="disabled" checked = '#currentScorec2#'/>
<cfinput type="radio" class="star" name="fairness" value="3" disabled="disabled" checked = '#currentScorec3#'/>
<cfinput type="radio" class="star" name="fairness" value="4" disabled="disabled" checked = '#currentScorec4#'/>
<cfinput type="radio" class="star" name="fairness" value="5" disabled="disabled" checked = '#currentScorec5#'/>
</cfform>
</div><!-- END div class="rating-wrapper" -->
<div class="rating-wrapper">
<cfform>
<label>Ethics</label>
<cfinput type="radio" class="star" name="ethics" value="1" disabled="disabled" checked = '#currentScored1#'/>
<cfinput type="radio" class="star" name="ethics" value="2" disabled="disabled" checked = '#currentScored2#'/>
<cfinput type="radio" class="star" name="ethics" value="3" disabled="disabled" checked = '#currentScored3#'/>
<cfinput type="radio" class="star" name="ethics" value="4" disabled="disabled" checked = '#currentScored4#'/>
<cfinput type="radio" class="star" name="ethics" value="5" disabled="disabled" checked = '#currentScored5#'/>
</cfform>
</div><!-- END div class="rating-wrapper" -->
....
</cfloop>
1 ответ
Разобрался: проблема была с моими динамическими переменными. Мне нужно было сбросить их в конце цикла:
<cfset "currentScore#score.leadership#" = "0">
<cfset "currentScoreb#score.communication#" = "0">
<cfset "currentScorec#score.fairness#" = "0">
<cfset "currentScored#score.ethics#" = "0">
<cfset "currentScoree#score.competence#" = "0">
</cfloop>