2017-10-04 18 views
6

Tôi không thể nhận dữ liệu interview_docs từ mảng php trong angularjs. tôi đã cố gắng nhiều json tùy chọn mã hóa nhưng nó didnt woked out.How để có được interview_docs dữ liệu trong js Đây là mảng của tôi:Mã hóa mảng php thành biến js Thiếu một số dữ liệu?

Array(
[id] => 1 
[tag] => 2 
[title] => Test 
[job_submission_id] => 0 
[job_id] => 14 
[candidate_id] => 55 
[mail_to] => [email protected] 
[cc_to] => [email protected] 
[interviewer] => [email protected] 
[interview_type] => 1 
[interview_date] => 2017-10-04 
[from_time] => 00:00:00 
[to_time] => 01:00:00 
[to_date] => 
[location] => 
[time_zone] => Asia/Kolkata 
[status] => 1 
[comments] => dwedfwef 
[created_by] => 1 
[modified_by] => 1 
[created_at] => 2017-10-03 12:21:13 
[updated_at] => 2017-10-03 12:21:13 
[job_title] => Test 
[candidate_name] => New t 

[candidates] => Array 
    (
     [id] => 55 
     [first_name] => New 
     [last_name] => t 
    ) 

[jobs] => Array 
    (
     [id] => 14 
     [code] => 10 
     [title] => Test 
    ) 

[interview_docs] => Array 
    (
     [0] => Array 
      (
       [id] => 1 
       [interview_id] => 1 
       [unique_name] => 2017_10_roa2XKlIDc9gmzmO7TK37rsfuX3YRigqUxbvIYWe.txt 
       [name] => first.png 
      ) 

     [1] => Array 
      (
       [id] => 2 
       [interview_id] => 1 
       [unique_name] => 2017_10_6RaAm3MU5ZZ1x4l3q8VLYNhUkgvS3v2ljNZVizm1.png 
       [name] => Screenshot (15).png 
      ) 

    ) 

)

khi tôi đã làm điều này: var data = <?php echo json_encode($array); ?>; console. log (dữ liệu); Tôi đang nhận được điều này

interview_docs:Array(0) 
length:0 
__proto__:Array(0) 

Tôi không thể nhận dữ liệu phỏng vấn từ mảng php trong angularjs. tôi đã cố gắng rất nhiều lựa chọn json mã hóa nhưng nó didnt woked out.How để có được dữ liệu interview_docs

+4

bạn cần phải sử dụng ** JSON_FORCE_OBJECT ** 'vang json_encode ($ mảng, JSON_FORCE_OBJECT) ' –

+0

không thay đổi @saad –

+1

bạn cần phải chứng minh làm thế nào bạn đang tạo ra' $ array'. Bạn đã thực hiện một 'print_r ($ array ['interview_docs'])' để đảm bảo nó thực sự chứa dữ liệu trước khi mã hóa nó? –

Trả lời

0

Trước tiên, bạn phải die() nó mã hóa để JSON và sau đó bạn có thể console.log() nó ở .js:

die(json_encode($array)); 
Các vấn đề liên quan