简体   繁体   English

在ATK4中重新加载网格

[英]Reload Grid in ATK4

I'm trying to learn enough to create a website that lets people answer quiz questions using Agile Toolkit 4.2. 我正在尝试学习足够的知识来创建一个网站,使人们可以使用Agile Toolkit 4.2回答测验问题。

I have a page that displays one question and its answer choices from the 'sampleq' model. 我有一个页面显示一个问题及其在“ sampleq”模型中的答案选择。 I want to make a button that displays the next record in the model. 我要创建一个显示模型中下一条记录的按钮。

I've tried a bunch of different ways to get the js()->reload() command to work properly, but I haven't been able to do it. 我尝试了多种方法来使js()-> reload()命令正常工作,但我一直无法做到这一点。 I get AJAX "unexpected identifier" error. 我收到AJAX“意外标识符”错误。 I've been through the related questions on this site and looked for documentation on the ATK site, but I haven't found an example that works for me. 我已经遍历了本网站上的相关问题,并在ATK网站上查找了文档,但是我还没有找到适合我的示例。

Can anybody tell me how to get the button to properly reload the grid? 有人可以告诉我如何获取按钮以正确地重新加载网格吗?

function init(){
    parent::init();
    $page=$this;
}

function page_qlisting() {

    $qid=$this->recall('value',1);
    echo $qid;
    $NextB=$this->add('Button')->SetLabel('Next Question '.$qid);

    $grid=$this->add('Grid');
    $grid->setModel('sampleq',array('question','A1','A2','A3'));
    $grid->dq->where('id=',$qid);

        if($NextB->isClicked()){
            //$this->memorize('value',$qid+1);
            $grid->js()->reload();
        }               
  }

function page_qentry() {

$this->api->auth->check();
$this->add('Html')->set('Welcome to the question entry page.<br>');
$this->add('CRUD')->setModel('sampleq');
}

} }

Edit: After reading Romans' answer, I first tried this: 编辑:阅读罗马书的答案后,我首先尝试了此操作:

$qid=$this->recall('value',1);
    $grid=$this->add('Grid');
            $grid->setModel('sampleq',array('id','question','A1','A2','A3'));
            $grid->dq->where('id=',$qid);
            $this->add('Button')->SetLabel('Next Question')->js('click', $this->memorize('value',$qid+1))->js('click', $grid->js()->reload());

That actually works - it displays only one record at a time, and it displays the next one when I click the button. 这实际上是有效的-一次只显示一个记录,而当我单击按钮时它显示下一个记录。 Next I tried adding a "Previous" button like so: 接下来,我尝试添加“ Previous”按钮,如下所示:

$qid=$this->recall('value',1);
        $grid=$this->add('Grid');
        $grid->setModel('sampleq',array('id','question','A1','A2','A3'));
        $grid->dq->where('id=',$qid);
        $this->add('Button')->SetLabel('Previous Question')->js('click', $this->memorize('value',$qid-1))->js('click', $grid->js()->reload());
        $this->add('Button')->SetLabel('Next Question    ')->js('click', $this->memorize('value',$qid+1))->js('click', $grid->js()->reload());

This doesn't work, though. 但是,这不起作用。 Both buttons are decrementing. 两个按钮都在递减。 I tried laying it out like your adjuster buttons example here . 我试图像这里调节器按钮示例一样进行布局。 Here's what my increment button code looks like in that attempt: 这是我的增量按钮代码在该尝试中的样子:

$incr=$this->add('Button')->SetLabel('Next Question');
        if($incr->isClicked()){
           $this->memorize('value',$qid+1);
           $grid->js()->reload();
           }

In that case, I get "Error in AJAXec response: SyntaxError: Unexpected identifier" when I click the button. 在这种情况下,当我单击按钮时,会收到“ AJAXec响应错误:语法错误:意外的标识符”。

Can you offer any advice on how to make increment and decrement work with a grid (or crud)? 您可以提供有关如何使网格(或粗粒)进行增量和减量的任何建议吗? Why doesn't the adjuster example work when you try to refresh a grid instead of refreshing the button? 当您尝试刷新网格而不是刷新按钮时,为什么调节器示例不起作用? Thanks for the previous answer, and thanks in advance for any additional guidance that you may have time to offer. 感谢您之前的回答,也感谢您可能有时间提供的其他指导。

This should be it: 应该是这样:

$this->add('Button')->js('click', $grid->js()->reload());

If you use CRUD you might want to reload CRUD instead. 如果使用CRUD,则可能需要重新加载CRUD。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM