You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Coldfusion多输入记录列表报错:isim值无法转换为数字(行11)

ColdFusion报错解决:值“isim”无法转换为数字

错误信息

Detail: The value isim cannot be converted to a number.
The error occurred on line 11.

问题原因

报错代码行是<cfset sef = ToString(attributes[key]["isim"])>,核心矛盾是表单提交的数据结构与循环逻辑不匹配:

  • 表单中输入框name="isim"提交后,attributes.isim是字符串类型的用户输入值,而非嵌套结构。
  • 当cfloop collection="#attributes#"遍历到key="isim"时,attributes[key]就是该字符串值,此时尝试用["isim"]访问其属性,ColdFusion会误将字符串当作数组处理,试图把字符串"isim"转换为数字索引,从而触发报错。
  • 额外问题:代码中存在多余的</tr>标签,无对应<tr>,需清理。

解决方法

步骤1:修正表单输入命名规则

根据重复器的多条目需求,将输入框name改为集合类型格式,确保提交后数据是数组/结构数组:

<cfform id="sef" action="#request.self#?fuseaction=#module_name#.emptypopup_add_sef" method="post">
  <div data-repeater-list="">
      <div data-repeater-item="">
            <cfoutput>
               <input name="entries[#repeaterIndex#].isim" type="text">
               <input name="entries[#repeaterIndex#].soyisim" type="text">
            </cfoutput>
          <hr>
      </div>
  </div>
</cfform>

注:repeaterIndex需替换为你使用的重复器插件提供的索引变量,或手动维护索引。如果是简单多输入场景,也可以用name="isim[]"、name="soyisim[]"的数组格式。

步骤2:调整循环逻辑

匹配新的表单数据结构,修改循环方式:

结构数组格式(推荐):

<cfloop array="#attributes.entries#" index="entry">
    <cfset sef = ToString(entry.isim)>
    <cfoutput>#sef#</cfoutput>
</cfloop>

简单数组格式:

<cfloop array="#attributes.isim#" index="isimVal">
    <cfoutput>#ToString(isimVal)#</cfoutput>
</cfloop>

步骤3:清理无效标签

删除代码中多余的</tr>标签,避免HTML结构错误。


内容的提问来源于stack exchange,提问作者Sefa KAÇMAZ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 14:10:20