1

我正在使用该插件x-editable,并且试图弄清楚如何将州名称列表加载到选择列表中以进行内联编辑。

基本上,我已经查询了数据库:

<cfquery datasource="#application.dsn.recAppTest#" name="states">
    SELECT * FROM dbo.states ORDER BY StateName ASC
</cfquery>

我设置了 HTML:

<label class="control-label" for="state">State:
    <a href="##" id="state" data-source="#states#">#session.state#</a>
</label>

这是jQuery:

$('#state').editable({
    name: 'state',
    type: 'select',
    placement: 'right',
    url: 'update-session.cfm',
    send: 'always'
});

请注意,这不起作用,它会产生此错误:

The expression has requested a variable or an intermediate expression result as a simple     
value, however, the result cannot be converted to a simple value. Simple values are   
strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects 
are examples of complex values. <p> The most likely cause of the error is that you are 
trying to use a complex value as a simple one. For example, you might be trying to use a 
query variable in a cfif tag.

此插件的数据源属性仅接受数组或对象(首选数组,因为对象可能会丢失排序)。

那么如何将我的coldfusion查询转换为“javascript数组”以用作数据源?

我唯一的想法是“构造”一个​​与数组语法匹配的字符串,但我试图避免这样的事情

4

1 回答 1

4

您需要将 JSON 传递到您的data-source属性中

<label class="control-label" for="state">State:
  <a href="##" id="state" data-source="#serializeJSON(states)#">#session.state#</a>
</label>

您可能需要对查询进行更多操作以使其按您希望的方式工作,但至少该data-source属性需要 JSON

于 2013-10-15T16:47:17.227 回答