【问题标题】:How to assign a value to a variable using CJavascriptExpression in yii如何在 yii 中使用 CJavascriptExpression 为变量赋值
【发布时间】: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-sourceFunction: 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


【解决方案1】:

我认为你的编码有问题。尤其是 source 部分

你可以参考下面的教程,他们是怎么做的 http://chevronscode.com/example-of-yii-autocomplete.html

【讨论】:

    猜你喜欢
    • 2015-01-11
    • 2016-11-21
    • 2017-02-19
    • 2012-12-27
    • 2018-06-18
    • 2016-03-17
    • 2013-02-25
    • 2013-04-28
    • 1970-01-01
    相关资源
    最近更新 更多