从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!
我正在使用x editable进行内联编辑。 p>
JQUERY strong> p>
这个运行正常。 但问题是,我想从 PHP strong> p>
我试过 通过在源中传递下面的变量,但它不起作用: p>
我如何实现这一目标? 我是否需要在
$('#status')。editable({
value:2,
source:[
{value:1,text:' 有效'},
{值:2,文字:'已屏蔽'},
{值:3,文字:'已删除'}
}
});
code> pre> \ n
php code>获取源选项。 为此我有一个数组。 p>
$ php_array = Array([MOBILE_TOPUP] =&gt ; MOBILE_TOPUP
[PICKUP] =&gt; PICKUP
[DELIVERY] =&gt; DELIVERY
[BANK_DEPOSIT] =&gt; BANK_DEPOSIT)
code> pre>
var json_array =&lt;?= json_encode($ php_array)?&gt ;;
code> pre >
PHP code>中更改数组结构? 谢谢你的帮助! p>
div>
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)?>';
You shouldn't use PHP inside JS, better to make an ajax call. This feature is built into x-editable if you use the source
option with a string like so:
$('#status').editable({
value: 2,
source: 'mypage.php'
});