1
Laravel 4에서 Knockout/Jquery를 사용하여 테이블을 채우려는 .ajax get을 수행하려고합니다. Ardent를 사용하고 다음 json 응답에 응답합니다.throwOnFind : 거짓 응답을 Laravel의 Ardent에서 가져 오기
{"throwOnFind":false}
컨트롤러 :
public function getData()
{
$roles = Role::select(array('roles.id', 'roles.name', 'roles.id as users', 'roles.created_at'));
return Response::json($roles, 200, array('Content-Type' => 'application/json'));
}
자바 스크립트는 :
function Role(data) {
this.id = ko.observable(data.id);
this.name = ko.observable(data.name);
this.users = ko.observable(data.users);
this.created_at = ko.observable(data.created_at);
}
function ViewModel() {
var self = this;
self.roles = ko.observableArray([]);
$.ajax({
type: "GET",
url: "{{ URL::to('admin/roles/data') }}",
complete: function(allData) {
var mappedRoles = $.map(allData, function(item) {
return new Role(item);
});
}
}, "json");
self.roles(mappedRoles);
}
ko.applyBindings(new ViewModel());
정말 당장은 모른다. 나는이 문제가 열렬히 일어날 수 있다고 생각한다.
:
그래서 당신은 뭔가 liek을 작성해야합니다. 또한 이것을 표시하기 위해 Knockout 용 매핑 플러그인을 사용해야했습니다. – Chris