【发布时间】:2014-01-09 05:45:43
【问题描述】:
我正在使用 yii,我正在使用 CJuiAutocomplete。我正在尝试在小部件中创建 动态源,但无法这样做。所以我在以下问题上需要帮助。这是代码
$this->widget('zii.widgets.jui.CJuiAutoComplete',array(
'name'=>'search Type',
'source'=>new CJavaScriptExpression("function(){
var name=$('#myname').val();
if(name==='ajeet')
{
$.ajax({
url: 'http://localhost/exhibition/admin/exhibitors/default/target',
data: {
list: 'exhibitor'
},
type: 'POST',
dataType: 'json',
success: function(data){
// how to assign the result i.e data to the source
}
});
}
}"),
'options'=>array(
'minLength'=>'1',
'select'=>'js:function(){
alert("ajeet");
}'
),
'htmlOptions'=>array(
'style'=>'height: 20px;',
),
));
服务器正在发送所需的结果,因为我已经检查了很多次。所以服务器脚本没有错误。
问题:- 因为我使用了 CJavascriptExpression 并使用第一次,不知道怎么把它返回的值赋给source。我在成功部分从 Ajax 获得了所需的结果但不知道如何使用它或将其分配给源。
注意:-我已经尝试过使用return data;
【问题讨论】:
-
你尝试选项
sourceUrl => 'http://localhost/exhibition/admin/exhibitors/default/target'吗? -
还要检查自动完成手册:api.jqueryui.com/autocomplete/#option-source
Function: The third variation, a callback, provides the most flexibility and can be used to connect any data source to Autocomplete. The callback gets two arguments:
标签: javascript jquery yii yii-extensions