0

我在我的应用程序中使用日期选择器进行引导。这是我的 HTML 代码:

<div class="input-append date pull-right" id="dp3" data-date-format="dd-mm-yyyy">
   <input name="dataregisto" id="dataregisto" class="span2" size="16" type="text" readonly>
   <span class="add-on"><i class="icon-th"></i></span>
</div> 

因此,当我保存数据时,它可以正常工作,但是当我编辑记录时,日期不显示。另一方面,所有剩余的数据都被填充。我的 JavaScript 代码:

(function($) {
    $(document).ready(function() {
        var today = new Date();
        var t = today.getDate() + "-" + (today.getMonth() + 1) + "-" + today.getFullYear();
        $("#dp3").datepicker()
                .on('show', function(ev) {

            $('#dp3').data({date: t}).datepicker('update');
        });

         //    $('#timepicker1').timepicker();


        document.getElementById("dataregisto").value = document.getElementById("dataregisto").defaultValue = t;
    });

})(jQuery);

控制器

 function edit($id = null) {

    session_start();
    if (isset($_SESSION['username'])) { /* verifica se existe uma sessão */
        $this->Registo->id = $id;
        if (empty($this->data)) {
            /* acede aos projetos */
            $this->set('projects', $this->Registo->Project->find('list', array('fields' => array('pname'))));
            /* acede ás versoes do projecto a editar */
            $this->set('projectversions', $this->requestAction("/ProjectVersions/getversionsofproject", array('projects' => $this->Registo->read()['Registo']['projects'])));
            /* acede aos clientes */
            $this->set('clients', $this->requestAction("/CustomFieldOptions/getClients"));
            /* acede ás issuetypes */
            // $issuetype= $this->requestAction("/Projects/getissuetypeofproject", array('projects' => $this->Registo->read()['Registo']['projects']));

            $this->set('dataregisto', $this->Registo->read()['Registo']['dataregisto']);
            /*  $issuetype = array();

              foreach($IssueTypes as $value) {
              $value = $value['IssueType']['id'];
              $issuetype[$value['IssueType']['id']] = $value['IssueType']['pname'];
              }


              debug($issuetype); */

            $this->set('issuetype', $issuetype);
            $this->request->data = $this->Registo->read();
        } else {
            if ($this->Registo->save($this->request->data)) {
                $this->Session->setFlash(__('Registo alterado com sucesso', true), 'flash_success');
                $this->redirect(array('action' => 'index'));
            } else {
                $errors = $this->Registo->invalidFields();
                $this->Messages->customize_error_msg($errors['issuetype']);
            }
        }
    } else {
        $this->redirect(array('controller' => 'users', 'action' => 'login'));
        // $this->Session->setFlash(__('Por favor efetue LOGIN para poder aceder a esta página!', true), 'flash_success');
    }
}

谢谢!

4

1 回答 1

0

你确定,你保存插入的数据,例如。在 dd-mm-yyyy 格式的 MySQL 数据库中?那可能是解决方案,或者您检测到错误。

编辑:查看文档

(function($) {
    $(document).ready(function() {
        var today = new Date(),
t = today.getDate() + "-" + (today.getMonth() + 1) + "-" + today.getFullYear();
        $("#dp3").datepicker().on('show', function(e) {
            e.preventDefault();
            $(this).datepicker('setValue', t);
        });
        document.getElementById("dataregisto").value = document.getElementById("dataregisto").defaultValue = t;
    });
})(jQuery);
于 2013-05-21T10:21:15.587 回答