English 中文(简体)
Yii CJUUAUU 完成不工作
原标题:Yii CJuiAutoComplete not working
  • 时间:2012-05-25 14:22:01
  •  标签:
  • jquery
  • yii

我试图在我的项目中执行 CJUIAUTO Compllete 软件,但是它行不通。 在过去几天里我研究了这个问题,并尝试了一切。 似乎正在发生( 或者没有发生)的是, 控制器的搜索动作没有被调用 。 如果我将源代码设置为简单的项目系列, 我也无法让它工作 。 我做错什么了?

_form.php 格式化(_f)

            <?php $this->widget( zii.widgets.jui.CJuiAutoComplete , array(
                         model  => $model,
                         attribute  =>  zipcode ,
                         source  => $this->createUrl( address/lookup ),
                         name  =>  zipcode ,
                         htmlOptions  => array( size => 5 ),
                         options  => array(
                             showAnim => fold ,
                             minLength  => 1,
                    )) ?>

地址控制器.php

public function accessRules()
{
    return array(
        array( allow ,  // allow all users to perform  index  and  view  actions
             actions =>array( index , view ),
             users =>array( * ),
        ),
        array( allow , // allow authenticated user to perform  create  and  update  actions
             actions =>array( create , update , lookup ),
             users =>array( @ ),
        ),
        array( allow , // allow admin user to perform  admin  and  delete  actions
             actions =>array( admin , delete ),
             users =>array( admin ),
        ),
        array( deny ,  // deny all users
             users =>array( * ),
        ),
    );
}


    public function actionLookup()
    {
        echo "Lookup Action";
    }
问题回答

Ah,jui s 自动完成 期待数据格式如下:

<强度 > 预期数据格式

来自本地数据的数据、URL或回调可以分为两种变式:

An Array of Strings: [ "Choice1", "Choice2" ]
An Array of Objects with label and value properties: [ { label: "Choice1", value: "value1" }, ... ]

所以,在你的行动中,你必须返回Json:

echo CJSON::encode(array("Look up action"));

编辑:>CJSON docs

试试这个很简单的...

public function actionAutoCompleteLookup()
        {
           if(Yii::app()->request->isAjaxRequest && isset($_GET[ q ]))
           {

              $name = $_GET[ q ]; 

               $qtxt ="SELECT name FROM address WHERE name LIKE  %".$name."% ";
               $command =Yii::app()->db->createCommand($qtxt);

               $userArray =$command->queryColumn();

              $returnVal =   ;
              foreach($userArray as $userAccount)
              {
                 $returnVal .= $userAccount->getAttribute( first_name ). | 
                                             .$userAccount->getAttribute( user_id )."
";
              }
              echo $returnVal;
           }
        }

在视觉代码中像这样...

<?php $this->widget( CAutoComplete ,
          array(
                         //name of the html field that will be generated
              name => name , 
                       //replace controller/action with real ids
              url =>array( address/AutoCompleteLookup ), 
              max =>10, //specifies the max number of items to display

                         //specifies the number of chars that must be entered 
                         //before autocomplete initiates a lookup

             ));
    ?>

它的工作很好......

Jquery Problem 请打开或删除 jquery-min.js 文件, 然后检查其工作是否正常 。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签