當然,你可以檢查像laroute
包您可以爲JavaScript端任何這樣的行動路線:
/**
* laroute.action(action, [parameters = {}])
*
* action : The action to route to.
* parameters : Optional. key:value object literal of route parameters.
*/
laroute.action('[email protected]');
編輯:實例添加
我有「主「頁面模板複雜的設計(在此簡化)
<div class="panel">
<div class="panel-heading"></div>
</div>
<div class="panel-body">
<div id="items-table">
@include('_items_list', compact(['items']))
</div>
</div>
我有一個項目在部分刀片模板(也簡化)
//_items_list.blade.php
<table class="table" >
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
@foreach($items as $item)
<tr>
<td >
{{ $item->id }}
</td>
<td>
{{ $item->name }}
</td>
<td>
<a href="javascript:void(0)" class="btn btn-danger items" data-item_id="{{ $item->id }}">Delete</a>
</td>
</tr>
@endforeach
</tbody>
</table>
在我的路線我使用POST方法的列表,但更好的方法是使用一個resourceful controller實現REST方法,你只能使用你想要的方法。
//routes.php
Route::post("items/delete.", "[email protected]");
在我的控制器我有一個刪除方法(也簡化)
//app/controllers/ItemsController.php
class ItemsController extends BaseController {
public function delete(){
$item = Item::find(Input::get('item_id'));
if($item) {
$item->delete();
//return the new items list
$items = Tramite::orderBy('created_at','desc')->paginate(10);
return View::make('_items_list', compact($items));
}
}
}
在我的js文件我有一個jquery事件監聽器這樣
//public/js/items.js
$(function() {
$('.items').click(function(ev){
var item_id = $(this).data('item_id');
//Here comes the laroute library!
//@see http://api.jquery.com/load/
$("#items-table").load(laroute.action('[email protected]', {'item_id': item_id}, function() {
console.log('New table loaded!');
});
});
});
角是唯一的JS框架我已廣泛使用。當然,沒有什麼能夠強制你使用它的所有功能。核心文件甚至不包括路由器。我懷疑其他框架也會很好。公平的警告。如果你對角度感到滿意,那麼我懷疑你的Laravel觀點會開始看起來不那麼吸引人。 – Cerad
react.js怎麼樣?我用了很長一段時間。這是一個很棒的框架,但有時它會提供一些你甚至不需要的額外功能。骨幹也可能工作。 –
@NaingLinAung我在想React JS(它對組件有一個狀態控制),但現在我要去尋找其他框架。謝謝! –