0

从 jQuery .get() 调用返回时,我遇到了 cfinput 标记的问题。如果我像这样将标签放在主页上:

<cfform>
    <cfinput type="text" name="txtinputfilter" autosuggest="cfc:#Application.cfcDir#autoSuggest.lookupTailNumber({cfautosuggestvalue})" > 

标签正确加载,自动建议按预期工作。但是,如果我将完全相同的标签(仅此而已)放在名为 common/includes/FilterData.cfm 的单独模板中,并从主页中调用它,如下所示:

<div id="txt_input_container"></div>
$(document).ready(function(){
    //the following get call is normally called on another select input's onchange
    $.get('common/includes/FilterData.cfm',
        //note that the following parameters are not being used in this example
        {column: selectedValue,
         filterValue: filterValue,
         filterID: filterID,
         configFile: 'Tracking/config/GeneralMaint.xml'},
        function(response){
            $('#txt_input_container').empty().append(response);
        }
    );
});

标签加载,但自动建议不起作用。控制台显示我得到了另外八个电话:

http://localhost/CORE/common/includes/FilterData.cfm?column=SERIAL_NUMBER&filterValue=&filterID=fi_1&configFile=Tracking%2Fconfig%2FGeneralMaint.xml

http://localhost/CFIDE/scripts/ajax/yui/yahoo-dom-event/yahoo-dom-event.js?_=1318592952367

http://localhost/CFIDE/scripts/ajax/yui/animation/animation-min.js?_=1318592952634

http://localhost/CFIDE/scripts/ajax/yui/autocomplete/autocomplete-min.js?_=1318592952706

http://localhost/CFIDE/scripts/ajax/messages/cfmessage.js?_=1318592952745

http://localhost/CFIDE/scripts/ajax/package/cfajax.js?_=1318592952782

http://localhost/CFIDE/scripts/ajax/package/cfautosuggest.js?_=1318592952821

http://localhost/CFIDE/scripts/cfform.js?_=1318592952859

http://localhost/CFIDE/scripts/masks.js?_=1318592952907

后跟此错误消息:

_cf_resetLoadingIcon_1318592952305 is not defined
[Break On This Error] /* ]]> */</script> 
4

1 回答 1

1

这不会是你想听到的答案。

为了让您动态显示 jQuery .get() 操作的结果,并使新的 javascript 生效,影响新显示的 HTML 的事件必须在初始 .get() 的结果处理程序期间绑定。通常,这是可行的......类似于以下内容:

 $.get('common/includes/FilterData.cfm',
        {column: selectedValue},
        function(response){
           $('input').change(function(event){
              ...addtl. logic here
           }

您会找到一种方法来指向/调用您在更改事件绑定中的新函数,该绑定是由于您的初始 .get() 调用而加载的全新输入字段。

当涉及到 CFML 时,这就变得混乱了。cfform/cffinput,当与 autosuggest 参数结合使用时...手动为您构建 javascript...自动。然而,对于这个代码的生成并没有真正的控制——CF 会任意命名它。当我输入你的代码进行测试时,我得到了一个名为 _cf_autosuggest_init_1318614417652 的函数......对你来说也一样吗?(可能不是)。

因此,在 .get() 的结果上动态绑定新的事件处理程序将非常困难——如果您不知道它们将被调用什么。

我的建议是重新设计您的 .get() 调用,这样您就不会加载 cfform/cfinput——但可能是原始数据本身——并将输入保留在父模板上,或者(深呼吸)......

...废弃 cfform/cfinput,并手动编写 jQuery 自动建议功能,以便您控制函数的名称——并且可以在动态绑定到它们时在 jQuery 结果处理程序中指向它们。

于 2011-10-14T18:03:55.203 回答