我正在寻找一个能够在组合(选择)中启用显示树的组件。 类似的东西:http://www.jeasyui.com/demo/index.php
但是这个组件不允许直接导入JSON,只能从文件导入。
它是这样工作的:
$('#cc').combotree({
url:'tree_data.json'
});
我需要(伪代码):
$('#cc').combotree({
data:'[{"id":1,"text":"City","children":[{"id":11,"text":"Wyoming","children":[{"id":111,"text":"Albin"}]}]}]'
});
或者(伪代码):
$('#cc').combotree({
data:'<?php $json_string; ?>'
});
这可能吗?或者,也许您知道能够做到这一点的任何组件?
问候, 克里斯
最佳答案
<?php
$obj = json_encode('['.json_encode($objects).']');
$jquery_obj = str_replace(",\\\"name\\\":", ",\\\"text\\\":", $obj);
print $jquery_obj;
?>
<script>
$(document).ready(function(){
var jq_data = $.parseJSON(<? print $jquery_obj; ?>);
$('#cc').combotree({
animate:true,
data:jq_data
});
});
</script>
<select id="cc" class="easyui-combotree"></select>
关于php - javascript(jquery)中的组合树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10073002/