【问题标题】:Coldfusion struct array errorColdfusion结构数组错误
【发布时间】:2014-07-25 17:33:35
【问题描述】:

我正在尝试构建数组来存储报告列名称,但出现以下错误:您试图取消引用类型为coldfusion.runtime 的标量变量。数组作为具有成员的结构。

我的代码是:

<cfscript>
        currentAssetNum  = 0;
        headerLabels     = "";
        headerUnderlines = "";
        reportContent    = "";

        columns = eqInventoryHelper.getPreformattedColumnCharacteristics(showComponents = variables.showComponents);

        // Get an array of the columns in the order they should be displayed.
        columnOrder = StructSort(columns, "numeric", "asc", "sortOrder");

        for (columnName in columnOrder) {
            //for (columnIndex=1; columnIndex <= StructCount(columns); columnIndex++){                          
            if (columns[columnName].justify == "left") {                        
                headerLabels &= LJustify(columns[columnName].label, columns[columnName].length) & " ";
            } else {                    
                headerLabels &= RJustify(columns[columnName].label, columns[columnName].length) & " ";
            }
            headerUnderlines &= RepeatString( "-", columns[columnName].length ) & " ";
        }       
        reportHeaders = headerLabels & variables.newLine & headerUnderlines;

    </cfscript> 

eqInventoryHelper.cfc:

<cffunction name="getPreformattedColumnCharacteristics" output="false">
    <cfargument name="showComponents" required="true"/>
    <cfscript>
        var columnSort = 1;         
        var columns = {
            asset_num = {label = "KFS Asset Number", length = 16, justify = "left", sortOrder = columnSort++},
            manufacturer_name = {label = "Manufacturer", length = 30, justify = "left", sortOrder = columnSort++},
            manufacturer_model_num = {label = "Model", length = 30, justify = "left", sortOrder = columnSort++},
            serial_num = {label = "Serial Number", length = 30, justify = "left", sortOrder = columnSort++},
            condition_code = {label = "Cond CD", length = 8, justify = "left", sortOrder = columnSort++},
            owner_chart = {label = "Owner", length = 6, justify = "left", sortOrder = columnSort++},
            owner_acct = {label = "Account", length = 10, justify = "left", sortOrder = columnSort++},
            cur_uc_fnd = {label = "UC Fund", length = 8, justify = "left", sortOrder = columnSort++},
            org_cd = {label = "Org Code", length = 10, justify = "left", sortOrder = columnSort++},
            custodial_code = {label = "Custodial Code", length = 15, justify = "left", sortOrder = columnSort++},
            pi_name = {label = "Principal Investigator", length = 30, justify = "left", sortOrder = columnSort++},
            uc_acquisition_code = {label = "Acq. Type", length = 10, justify = "left", sortOrder = columnSort++},
            received_date = {label = "Received Date", length = 14, justify = "right", sortOrder = columnSort++},
            asset_desc = {label = "Asset Description", length = 51, justify = "left", sortOrder = columnSort++},
            ucop_tag_num = {label = "UCOP Tag Number", length = 16, justify = "left", sortOrder = columnSort++},
            asset_location = {label = "Asset Location", length = 60, justify = "left", sortOrder = columnSort++},
            asset_type = {label = "Asset Type", length = 11, justify = "left", sortOrder = columnSort++},
            is_uc_title = {label = "UCD Title", length = 14, justify = "left", sortOrder = columnSort++},
            total_cost = {label = "Total Cost", length = 12, justify = "right", sortOrder = columnSort++},
            useful_life = {label = "Useful Life", length = 12, justify = "right", sortOrder = columnSort++}
        };

        // If showing components, we tack the component specific columns to the main columns array.
        if (arguments.showComponents) {
            columns.component_num = {label = "Component Number", length = 18, justify = "left", sortOrder = columnSort++};
            columns.component_desc = {label = "Component Description", length = 45, justify = "left", sortOrder = columnSort++};
            columns.component_manufacturer_name = {label = "Manufacturer Name", length = 18, justify = "left", sortOrder = columnSort++};
            columns.component_model_num = {label = "Manufacturer Model Number", length = 26, justify = "left", sortOrder = columnSort++};
            columns.component_serial_num = {label = "Serial Number", length = 20, justify = "left", sortOrder = columnSort++};
            columns.component_po_number = {label = "PO Number", length = 12, justify = "right", sortOrder = columnSort++};
        }
        return columns;
    </cfscript>
</cffunction>

谢谢。

【问题讨论】:

  • 第538行是哪一行?
  • 在 cfscript 第 538 行:for (columnName in columnOrder) {
  • 看起来你在参数 4 中传递的值在结构中不存在并且数组为空
  • 论据 4...您是指此代码中的 sortOrder 吗? ... columnOrder = StructSort(columns, "numeric", "asc", "sortOrder");...
  • 您是否查看了您尝试使用的各种变量的内容,并检查了其中的内容?如果您提供了,您不会说您做过或提供该信息。请相应地调查和更新问题。

标签: struct coldfusion cffunction


【解决方案1】:

我强烈怀疑您使用的 ColdFusion 版本早于 for(index in array) 语法。 This was only added in ColdFusion 9.0.1.

因此,如果您运行的是 9.0,它将无法工作,并且会假定您要迭代结构。

【讨论】:

  • 亚当可能是对的。转储您的完整版本号。文档说它是在ColdFusion 9 Update 1 中引入的。听起来你正在使用 9,0,0。
  • 干杯@Leigh:我已经相应地更新了我的答案。我第一次检查时找不到那个 ref。
  • 谢谢。是的,我的版本是 9,0,0,251028。
  • 语法“for(index in array)”有效,但不是“for(index in arraysort)”。
  • 我真诚地怀疑最后两个陈述是否准确。您能否运行此代码并发布结果:gist.github.com/daccfml/5321f6dcb24c724dc586
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多