我有jQuery选择以插入形式命名为centro medicos,我可以选择所有数据,选择一些数据.如果我点击这里选择全部是结果:
假设我只选择3个项目,然后保存.现在我想编辑.加载编辑页面时,我想要加载我选择的3个项目:
如果我点击全选(Selectionar待办事项),则会显示其余项目.
1-控制器
public function edit_form() { $edit_id= $this->uri->segment(3); $data['ITEM_EDIT'] = $this->model->get_title_by_id($edit_id); $data['ITEM_ALL']= $this->model->get_all_title(); $this->load->view('view_edit_form',$data); }
2-视图
<select class="chosen-select" multiple name="item[]"> <?PHP foreach($ITEM_ALL as $item_all) { foreach($ITEM_EDIT as $item_edit) { if($title_edit->title== $title_all->title) { echo '<option value="'.$item_all->title.'" class="'.$item_all->id.'" selected>'.$item_all->title.'</option>'; } else { echo '<option value="'.$item_all->title.'" class="'.$item_all->id.'" >'.$item_all->title.'</option>'; } } } ?> </select>
3- jQuery
$(".chosen-select").chosen({ no_results_text: "Oops,nothing found : ",})
我怎样才能做到这一点?
@Diasline
这段代码工作正常我已经检查了我的系统并重现了你得到的错误.
这是使用所选内容创建的示例代码.我通过单击按钮在此代码中给出了全选选项.这是代码通过它.
这段代码工作正常我已经检查了我的系统并重现了你得到的错误.
这是使用所选内容创建的示例代码.我通过单击按钮在此代码中给出了全选选项.这是代码通过它.
<html lang="en"> <head> <link rel="stylesheet" href="docsupport/style.css"> <link rel="stylesheet" href="docsupport/prism.css"> <link rel="stylesheet" href="chosen.css"> <button id="select-all">Select All</button><br/> <select data-placeholder="Chosen Example" multiple class="chosen-select" tabindex="18" id="multiple-label-example"> <option value="">American Black Bear</option> <option>Asiatic Black Bear</option> <option selected>Brown Bear</option> <option selected>Giant Panda</option> <option>Sloth Bear</option> <option>Sun Bear</option> <option>Polar Bear</option> <option>Spectacled Bear</option> </select> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.js" type="text/javascript"></script> <script src="chosen.jquery.js" type="text/javascript"></script> <script src="docsupport/prism.js" type="text/javascript" charset="utf-8"></script> <script src="docsupport/init.js" type="text/javascript" charset="utf-8"></script> <script> $('#select-all').click(function(){ $('#multiple-label-example option').prop('selected',true); // Selects all options $("#multiple-label-example").trigger("chosen:updated"); }); </script>
Here you can see on the click event of the button i’ve added a line to change all the options as selected and then a line below that to update the chosen. If you don’t give the last line i.e,if you don’t update the chosen it will not work. It will only work after updating the chosen.Hope this solves your issue .please let me know if the issue persists.