douai2499 2014-11-11 17:32 采纳率: 100%
浏览 91
已采纳

从x可编辑的php中获取选择选项

I am using x editable for inline editing.

JQUERY

$('#status').editable({
  value: 2,
  source: [
  {value: 1, text: 'Active'},
  {value: 2, text: 'Blocked'},
  {value: 3, text: 'Deleted'}
  ]
});

This one is running fine. But the problem is, I want to get source options from php. For that I have an array.

PHP

$php_array = Array ( [MOBILE_TOPUP] => MOBILE_TOPUP
                     [PICKUP] =>PICKUP
                     [DELIVERY] => DELIVERY
                     [BANK_DEPOSIT] => BANK_DEPOSIT )

I tried with by passing below variable in source but it's not working:

var json_array = <?=json_encode($php_array)?>;

How can I achieve this? Do I need to change array structure in PHP? Thanks for any help!

  • 写回答

2条回答 默认 最新

  • dongxianrang9269 2014-11-11 17:51
    关注

    Yes, you have to change array structure as below :

    $php_array = Array ( 
            array('value' => 1, 'text' => 'Active'),
            array('value' => 2, 'text' => 'Blocked'),
            array('value' => 3, 'text' => 'Deleted'),
    );
    
    var json_array = '<?=json_encode($php_array)?>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?