追加结构以创建新的结构集(如果存在) [英] Appending structure to create new set of structure if exists

查看:52
本文介绍了追加结构以创建新的结构集(如果存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查表单值,如果结构中存在其他表单值,则应附加其他值,并应创建该会话结构.使用以下代码,我正在尝试执行此操作:

I am checking the form value and if the different form value exists in the structure, it should append it else, it should create that session structure. With the following code, i am trying to do it:

<cfif session.box_status.partner_id NEQ "">
        <cfset session.box_status.partner_id = StructAppend(session.box_status.partner_id,FORM.partner_id,'No') />
     <cfelse>
        <cfset session.box_status.partner_id = FORM.partner_id />
     </cfif>

显然,上面的代码没有检查表单结构中是否存在相同的值,但这也给我一个错误:

Apparently above code does not checking if the same value is existing in the form structure or not, but it is also giving me an error:

You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members. 

更新#1

http://screencast.com/t/G50k5RCXROWQ

推荐答案

您正在将session.box_status.partner_id视为结构,但这是一个简单的值.会话是一个结构,但是您要特别使用的值是一个简单的字符串.只需使用listAppend.

You are treating session.box_status.partner_id as a struct, but it is a simple value. Session is a struct, but the value you are particularly working with is a simple string. Just use listAppend.

在评论中更多地谈论了Voeger之后,我们发现他想要一个数组结构.因此,他应该首先将值初始化为数组:

After talking more w/ voyeger in comments, we figured out he wanted an array of structs. So he should begin by initializing the value as an array:

session.box_status = arrayNew(1);

session.box_status = [];

然后他可以追加一个结构.

And he can then just append a struct.

newData = { // keys here };
arrayAppend(session.box_status, newData);

这篇关于追加结构以创建新的结构集(如果存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆