0

我正在使用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>
4

1 回答 1

0

想通了:问题出在我的动态变量上。我需要在循环结束时重置它们:

<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>
于 2012-10-16T22:39:33.023 回答