douai2499 2014-11-11 09: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 09: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部