miku 2012-09-14 16:07:04 3214次浏览 2条回复 0 0 0

我想用一个ajaxlink来为自己的表单添加行。点击一下就增加一行输入。我在controller中有个变量记录生成了几行。但是我发现第一次点击后变量变了,但是接下来再点,表单行能增加,但是controller中的变量还是第一次请求时候的值。代码如下: controller:

public function actionNewrow()
{
    $form = new CActiveForm();
    $temp = new exportprice();
    //array_push($this->exps, $temp);
    $this->exps[] = $temp;
    //echo count($this->exps);
    $i = count($this->exps)-1;
    $html = '<tr><td>'.$form->labelEx($this->exps[0],'['.$i.']productname').$form->textField($this->exps[0],'['.$i.']productname').$form->error($this->exps[0],'['.$i.']productname').'</td>'.
    '<td>'.$form->labelEx($this->exps[0],'['.$i.']trend').$form->textField($this->exps[0],'['.$i.']trend').$form->error($this->exps[0],'['.$i.']trend').'</td>'.
    '<td>'.$form->labelEx($this->exps[0],'['.$i.']margin').$form->textField($this->exps[0],'['.$i.']margin').$form->error($this->exps[0],'['.$i.']margin').'</td></tr>';
    echo $html;
}

View:

<?php
echo CHtml::ajaxLink("新增",
    Yii::app()->createUrl( 'InputReport/newrow' ),
    // ajax options
    array(
        'error' => 'function(data)   { alert("error!");  }',
        'success' => 'function(data) { $("#exptbl").append(data); }',
        'cache'=>false,
    ),
    // htmloptions
    array(
        'id' => 'handleClick',
        )
    );
?>

ajaxlink不管我点多少次,$i = count($this->exps)-1 这个值永远都是1。 我第一次接触yii,还请达人们指教啊。

  • 回复于 2012-09-14 16:07 举报

    $this->exps里包含的应该是所有的exportprice信息, 应该存起来,例如存到数据库里,下次通过Ajax请求的时候,就从数据库里读出来,再加上你的请求,$i就肯定会变化了。

  • 回复于 2012-09-14 16:38 举报

    exp的声明是static的么?

您需要登录后才可以回复。登录 | 立即注册