Jquery와 Ajax를 사용하여 Zend Framework 애플리케이션에서 동적 폼을 작성했지만 문제가 발생했습니다. 어떤 이상한 이유로 jquery는 datePicker와 같은 표준 Jquery 객체 중 하나를 추가하지 않으면 내 페이지에서 작동하지 않습니다.Zend Framework Jquery 로딩에 이상한 행동이 있습니다.
datepicker를 추가 할 때마다 코드가 제대로 작동하므로 datepicker를 제거하면 $(document).ready(function()
변수가 정의되지 않는다는 오류가 발생합니다. jquery가로드되지 않아서 변수가 브라우저에 이해가되지 않는다고 생각하면 그 자체로 정확합니다.
라이브러리, 부트 스트랩 및 echo $this->Jquery();
이 모두 적절하게 설정되어 있지 않으면 날짜 선택 도구가 작동하지 않으며 datepicker가 있고 다른 코드가 제대로 작동하면 완벽하게 설정됩니다.
Jquery가 제대로로드되지 않는 문제가있는 사람이 있습니까?
부트 스트랩에 내 코드:
protected function _initViewHelpers()
{
$view = new Zend_View();
$view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$viewRenderer->setView($view);
그리고 레이아웃에 내 코드 :
는<?php
echo $this->jQuery();
echo $this->layout()->content;
?>
내 application.ini 또한 autoloaderNamespaces[] = "ZendX"
라인 여기
그리고있다는 jQuery 코드입니다 내보기 :
<p>All fields are required.</p>
<?= $this->form; ?>
<script type="text/javascript">
$(document).ready(function() {
$("#addElement").click(
function() {
ajaxAddField();
}
);
$("#removeElement").click(
function() {
removeField();
}
);
}
);
// Get value of id - integer appended to dynamic form field names and ids
var id = $("#id").val();
// Retrieve new element's html from controller
function ajaxAddField() {
$.ajax(
{
type: "POST",
url: "<?=$this->url(array('action' => 'newfield', 'format' => 'html'));?>",
data: "id=" + id,
success: function(newElement) {
// Insert new element before the Add button
$("#addElement-label").before(newElement);
// Increment and store id
$("#id").val(++id);
}
}
);
}
function removeField() {
// Get the last used id
var lastId = $("#id").val() - 1;
// Build the attribute search string. This will match the last added dt and dd elements.
// Specifically, it matches any element where the id begins with 'newName<int>-'.
searchString = '*[id^=newName' + lastId + '-]';
// Remove the elements that match the search string.
$(searchString).remove()
// Decrement and store id
$("#id").val(--id);
}
</script>
간단한 _initViewHelpers()에서 마지막 줄에서이 설정! 고마워요 :) –