答案 0 :(得分:0)
我不知道这个插件,但看看这些例子似乎有一个适合你的需求; 示例6 - AJAX延迟加载&每个级别更改的设置值。
理论上,这只需要一些配置选项:
preselect: {'demo6': ['220','226']}, // array of default values - if on any level option value will be in this list, it will be selected
preselect_only_once: true, // prevent auto selecting whole branch when user maniputales one of branch levels
get_parent_value_if_empty: true,
attr: "id" // we'll use input id instead of name
如果这不适合您,您可以从事件中启动它,例如更改, keyup 等。
$(document).on('change', '#select', function() {
$('#nextSelect').val($(this).val());
})
$(document).on('change', '#nextSelect', function() {
$('#finalInput').val($(this).val());
})
答案 1 :(得分:0)
是的,你是对的Mackan!我看到了"预选"选项,但我最初无法使用它将数据库中的路径转移到javascript,我最终得到了我的" newbie"解决方案匹配语法:
preselect: {'parent_category_id': [0,'2','22']},
PHP
$ category_path来自数据库查询,就像" 0,2,76,140,"
$path = explode(',', $category_path);
$preselect="";
foreach ($path as $value) {
$int = (int)$value;
if ($int != 0) $preselect.= "'". $int ."',";
else $preselect.= $int.","; // have to do this as ZERO in my case has to be without apostrophes ''
}
$preselect = "{'parent_category_id':[".$preselect."]}"
JS
var presel= <?php echo($preselect); ?>;
var options = {
preselect: (presel),
}
有关更好代码的任何建议吗? 非常感谢!!