weixin_33726313 2018-09-07 08:20 采纳率: 0%
浏览 22

Nette-摘要更新

I have a problem with snippet updating. After changing the selection in the select box, I redraw the contents of options in another select box but the snippet doesn't update.

Latte:

<form class="df-checkout">
...

<select n:href="getHraci!" name="domaci" id="domaci" class="form-control">
    <option value="">Vybrat</option>
    <option n:foreach="$tymy as $tym" value="{$tym->getId()}">
        {$tym->getNazev()}
    </option>
</select>

...

<div class="row helpers hidden">
    <select n:snippet="hraciDomaci" class="form-goly-domaci-select form-control">
        <option></option>
        <option n:foreach="$hraciDomaci as $hrac" value="{$hrac->getId()}">
            {$hrac->getPrijmeni()} {$hrac->getJmeno()}
        </option>
    </select>

    <input type="text" class="form-goly-input form-control">
</div>

JS file:

$(document).ready(function(){
    $("#domaci").bind('change', function() {
        var link = $(this).attr("href");

        $.nette.ajax ({
            url: link,
            data: {"strana": "domaci", "tymId": $(this).val()},
            type: 'get',
            dataType:'json'
        });
    });
});

Controller:

public function handleGetHraci($strana, $tymId)
{
    $tym = $this->tymManager->getTymRepository()->find($tymId);
    $muzstvo = $this->tymManager->getMuzstvoRepository()->findBy(["nazev" => self::HLAVNI_TYM]);
    $hraci = $this->hracManager->getHracRepository()
                ->findBy(["tym" => $tym, "muzstvo" => $muzstvo], ["prijmeni" => "ASC", "jmeno" => "ASC"]);

    if($this->isAjax()){
        $this->template->hraciDomaci = $hraci;

        $this->redrawControl('hraciDomaci');
    }
}

The form has not yet been created and processed, so the first select box I have done is temporarily and select box with the snippet is independent on the form. I use it for copying. JS calls the handler correctly, and if I dump $this->template->hraciDomaci before redrawControl the data is there, but redrawControl will not do anything. But a new line with the process is added to the page in the lower Tracy bar. I do not have a bug in my debugger, the process has status 200 but response contains only:

{"state":[],"snippets":{"snippet--hraciDomaci":"\t\t\t\t\t\t\t\t\t\t<option></option>
"}}

I tried to use $.get instead of $.nette.ajax, wrap in snippetArea and I normally have this code in {block content}, so snippetArea should not be needed. nette.ajax.js with initialization $.nette.init(); I have too.

Thanks a lot for any advice.

  • 写回答

1条回答 默认 最新

  • Lotus@ 2018-09-07 08:52
    关注

    check that you are not rewriting hraciDomaci variable in render* method (e.g. renderDefault) in the presenter

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog