更改类别选择表单后,我无法选择子类别
public class LocaleTest extends JFrame {
private static final long serialVersionUID = 1L;
public LocaleTest() {
super("test");
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
add(new MainPanel());
pack();
setLocationRelativeTo(null);
setVisible(true);
}
private class MainPanel extends JPanel implements LocaleChangeable {
private JLabel label;
private JButton changeLocaleButton;
public MainPanel() {
super(new FlowLayout());
label = new JLabel(Locale.ENGLISH.toString());
add(label);
changeLocaleButton = new JButton("Change Locale");
changeLocaleButton.addActionListener(e -> {
broadcastLocaleChange(Locale.CANADA);
});
add(changeLocaleButton);
}
@Override
public void localeChanged(Locale newLocale) {
label.setText(newLocale.toString());
System.out.println("Language changed.");
}
private void broadcastLocaleChange(Locale locale) {
List<Component> components = getChildren(Component.class, LocaleTest.this);
components.stream().filter(LocaleChangeable.class::isInstance).map(LocaleChangeable.class::cast)
.forEach(lc -> lc.localeChanged(locale));
}
}
private static <T extends Component> List<T> getChildren(Class<T> clazz, final Container container) {
Component[] components;
if (container instanceof JMenu)
components = ((JMenu) container).getMenuComponents();
else
components = container.getComponents();
List<T> compList = new ArrayList<T>();
for (Component comp : components) {
if (clazz.isAssignableFrom(comp.getClass())) {
compList.add(clazz.cast(comp));
}
if (comp instanceof Container)
compList.addAll(getChildren(clazz, (Container) comp));
}
return compList;
}
public static interface LocaleChangeable {
void localeChanged(Locale newLocale);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new LocaleTest().setVisible(true));
}
}
答案 0 :(得分:0)
$.ajax({
type:"GET",
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
url:"{{url('get-categorie-list')}}?cat_id="+cat_id,
dataType:"json",
答案 1 :(得分:0)
文件wib.php
Route::get('get-categorie-list/{cat_id}','AnnonceController@getSubcatList');
html
<div class="form-group">
<label for="cat" class="col-md-3 control-label">Catégorie</label>
<div class="col-sm-6">
<select name='categorie_id' class="form-control" id='categorie' placeholder = 'Sélectionner votre categorie'>
<option>Sélectionner votre categorie</option>
@foreach($categories as $categorie)
<option value="{{ $categorie->id }}"> {{ $categorie->name }}</option>
@endforeach
</select>
</div>
</div> <!-- form-group // -->
<div class="form-group">
<label for="cat" class="col-md-3 control-label">Sous Catégorie</label>
<div class="col-sm-6">
<select name='subcategorie_id' class="form-control" id="subcategorie">
</select>
</div>
</div>
<div class="form-group">
我的控制器:
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\State;
use App\Categorie;
use App\SubCategorie;
use App\Http\Requests;
use DB;
class AnnonceController extends Controller
{
public function getSubcatList(Request $request)
{
$subcategories =SubCategorie::where('categorie_id','=',$request->cat_id)->get();
return response()->json($subcategories);
}