나는이 배열을 PHP에서 생성하고 "$ auction_additionalrevenues"라는 변수에 저장했습니다. 이 배열을 사용하여 부트 스트랩을 사용하여 매우 훌륭한 데이터 테이블을 생성했습니다.배열 처리 PHP에서 자바 스크립트
나의 궁극적 인 목표는 사용자가 상기 데이터 테이블의 행을 클릭 한 다음 모달을 사용하여 편집을 허용 한 다음 테이블에서 다음 행을 만들 수 있도록하는 것입니다.
FileMaker를 db 소스로 사용하여 테이블의 행이 "관련 데이터"이거나 사용자가보고있는 상위 레코드의 하위 레코드 인 경우를 여러 번했습니다. 이번에는 데이터가 관련이 없지만 다차원 배열을 만든 "반복 필드"의 부모 레코드 자체에 있습니다.
나는이 특정 인스턴스에서 제대로 된 것처럼 보이지 않는데, 사용자가 클릭 한 특정 행에 대한 데이터를 모델에 표시하는 방법입니다. 전역 변수에 저장되어있는 다중 - 차원 적 (또는 중첩 된) PHP 배열의 모든 데이터를 가지고 있기 때문에 좌절감을 느낍니다. 즉, 이미 배열/변수에있는 데이터를 가져 오기 위해 DB로 돌아갈 필요가 없습니다.
렌더링 된 페이지/Javascript/PHP간에이 데이터를 모두 전달하려면 어떻게해야합니까? 아래의 "onclick"을 통해 JS의 레코드/행을 쉽게 에코 할 수 있습니다.
의 onclick = showadrev()
내가 콘솔 로그에 $의 mkey ($ mkey = 인덱스/행)을 작성하거나 아무 문제가 그것을 경고 수 없다고 할
.다음 그 모달 popover가 해당 인덱스/행에 중첩 된 배열을 표시하기를 원합니다. 여기
내 배열 :Array
(
[0] => Array
(
[0] => Raffle
[1] => Pick of Live
[2] =>
[3] => 100
[4] => 150
[5] => Cocktail Only
[6] => Struggled a bit, offered some from the stage to hit the minimum
)
[1] => Array
(
[0] => Raffle
[1] => Ticket/Tangible
[2] => $1000 gift certificate to Canlis
[3] => 25
[4] => Unlimited
[5] => Cocktail Only
[6] => Really don't know how this did, but the box was pretty full of tickets
)
[2] => Array
(
[0] => Game
[1] => Ticket/Tangible
[2] => The Horse Race. Everyone is a winner. Receive a gift certificate ranging from $25 to $99.
[3] => 25
[4] => Unlimited
[5] => Cocktail Only
[6] => Great participation
)
[3] => Array
(
[0] => Other
[1] => Mystery/ Blind Pull
[2] => Wine Pull
[3] => 25
[4] => 50
[5] => cocktail only
[6] => There was about a dozen or so left
)
[4] => Array
(
[0] => Other
[1] => Ticket/Tangible
[2] => Centerpiece sales
[3] => 25
[4] => 35
[5] => Pre & During
[6] => Unknown
)
)
그리고 여기에 데이터 테이블은 내가 표현하고있다 :
<div class="wizard-step-3">
<fieldset>
<legend class="pull-left width-full">Aditional Revenue</legend>
<!-- <div class="table-responsive"> -->
<table id="data-table" class="table table-bordered table-striped" width="100%">
<thead>
<tr>
<th>Item</th>
<th>Type</th>
<th>Title</th>
<th>Price</th>
<th>Total Available</th>
<th>Sold By</th>
<th>Description</th>
<th>How did it Go?</th>
</tr>
</thead>
<tbody>
<?php foreach ($auction_additionalrevenues as $mkey => $adrevitems){
$no = $mkey + 1;
?><tr style="cursor:pointer;" onClick=showadrev(<?php echo $mkey ; ?>)><?php;
echo '<td>'.$no.'</td>';
echo '<td>'.$adrevitems[0].'</td>';
echo '<td>'.$adrevitems[1].'</td>';
echo '<td>'.$adrevitems[3].'</td>';
echo '<td>'.$adrevitems[4].'</td>';
echo '<td>'.$adrevitems[5].'</td>';
echo '<td>'.$adrevitems[2].'</td>';
echo '<td>'.$adrevitems[6].'</td>';
echo '</tr>';
} ?>
</tbody>
</table>
<!-- </div> -->
</fieldset>
</div>
json_encode없이 JS에 배열을 직접 전달하면 ("mkey"와 함께) Uncaught SyntaxError : 예상치 못한 토큰 u가 위치 0에서 JSON에 도착하지만 json_encode가있는 JS에 전달하면 얻을 수 있습니다. "잡히지 않은 SyntaxError : 유효하지 않거나 예기치 않은 토큰"이 콘솔 로그에 있습니다. – user11226
전체 배열을 자바 스크립트 변수에 저장하는 방법을 묻고 있습니까? 'var data = [[Raffle, ..], ....]' – ArtisticPhoenix
도 "typeof"를 알면 "Function"을 얻습니다. – user11226