冷聚变Ajax:如何在绑定选择框中获取空白行?
我有两个使用绑定的 cfselect 框和一个 cfc。一是国家。选择一个州,然后会动态填充第二个 cfselect(县)。
在使用绑定属性执行此操作之前,我依靠 queryPostion="below" 属性(如下所示)基本上将一个空白行放入选项框中。我现在想对“州”和“县”选择框执行相同的操作,因为我希望在每个选择框中都有“”值(或“ALL”值作为选项)。但是 queryPostion 不再起作用。 我不确定有什么解决方法。
//original... leaves a blank option:
<cfselect enabled="No" name="search_state" multiple="no" query="get_States" value="StateUSAbb" display="StateName" queryPosition="below">
<option></option>
</cfselect>
//now, w/bind, doesn't work:
<cfselect bind="cfc:states.getStates()" bindonload="true" name="search_state"
value="StateUSAbb" display="StateName">
</cfselect>
<cfselect bind="cfc:states.getCounties({search_state})" bindonload="true" name="search_county" value="FIPS_County" display="CountyName" >
</cfselect>
更新 两个查询的解决方案:
SELECT DISTINCT tblLoc.StateUSAbb, lkuState.StateName
FROM lkuState INNER JOIN tblLoc ON lkuState.FIPS_State = tblLoc.FIPS_State
WHERE (lkuState.StateName <> 'New Brunswick')
UNION
SELECT '' AS StateUSAbb, '' AS StateName
FROM lkuState
ORDER BY StateName
SELECT '' AS FIPS_COUNTY, '' as CountyName
FROM lkuCnty
UNION
SELECT FIPS_County, CountyName
FROM lkuCnty
WHERE StateAbb = '#ARGUMENTS.stateabb#'
ORDER BY CountyName
I have two cfselect boxes that use binds and a cfc. One is State. Choose a State, and the second cfselect (counties) is populated on the fly.
Prior to doing this with the bind attribute, I relied on the queryPostion="below" attribute such as the following to basically put a blank row into the option box. I want to do the same thing for both the State and County select boxes now, as I'd like to have "" values (or an "ALL" value as an option in each. But queryPostion no longer works.
I'm not sure of a work-around.
//original... leaves a blank option:
<cfselect enabled="No" name="search_state" multiple="no" query="get_States" value="StateUSAbb" display="StateName" queryPosition="below">
<option></option>
</cfselect>
//now, w/bind, doesn't work:
<cfselect bind="cfc:states.getStates()" bindonload="true" name="search_state"
value="StateUSAbb" display="StateName">
</cfselect>
<cfselect bind="cfc:states.getCounties({search_state})" bindonload="true" name="search_county" value="FIPS_County" display="CountyName" >
</cfselect>
UPDATE
Solution for both queries:
SELECT DISTINCT tblLoc.StateUSAbb, lkuState.StateName
FROM lkuState INNER JOIN tblLoc ON lkuState.FIPS_State = tblLoc.FIPS_State
WHERE (lkuState.StateName <> 'New Brunswick')
UNION
SELECT '' AS StateUSAbb, '' AS StateName
FROM lkuState
ORDER BY StateName
SELECT '' AS FIPS_COUNTY, '' as CountyName
FROM lkuCnty
UNION
SELECT FIPS_County, CountyName
FROM lkuCnty
WHERE StateAbb = '#ARGUMENTS.stateabb#'
ORDER BY CountyName
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想出的最简单的方法是在 cfc 的查询中插入空白(或占位符)数据行。像这样的东西:
The easiest way I've figured out is to insert a blank (or placeholder) data row in the query in your cfc. Something like:
这将在 states.cfc getCounties() 函数中处理。即需要返回空白记录。如果您需要更多帮助,请在此发布。
This would be handled in the states.cfc getCounties() function. That needs to return the blank record. Post it here if you want more help.
更新:没关系。看起来我在回复时已经提出了同样的建议;-)
AFAIK,没有用于在绑定选择列表中创建空元素的内置选项。至少CF8不是这样。
由于绑定将替换列表内容,因此您需要将空选项添加到查询结果中。一种技术是通过 UNION 将空选项添加到查询结果中。
根据列表值,
...或者可能
更新
有趣的是,使用 UNION 和 UNION ALL 之间的区别在于 UNION 会删除重复项。 UNION ALL 没有。由于 UNION 查询稍微昂贵,我只在需要时使用它。
UPDATE: Never mind. Looks like the same was already suggested while I was replying ;-)
AFAIK, there is no built in option for creating empty elements in bound select list. At least not with CF8.
Since binding will replace the list contents, you would need to add the empty options to your query results. One technique is to add the empty option to your query results via a UNION.
Depending on the list values, either
... OR possibly
UPDATE
As a point of interest, the difference between using UNION and UNION ALL is that UNION removes duplicates. UNION ALL does not. Since a UNION query is slightly more expensive, I only use it when needed.
仅供参考,绑定表达式可以绑定到返回 CF9 中实体数组的函数。
在这种情况下,ArrayPrepend() 的工作方式与 QoQ w/ UNION ALL 相同。
FYI bind expression can bind to functions that returns an array of entities in CF9.
In that case, ArrayPrepend() will work the same as QoQ w/ UNION ALL.