Jquery 获得一个throwOnFind:来自Ardent在Laravel的错误回应

Jquery 获得一个throwOnFind:来自Ardent在Laravel的错误回应,jquery,knockout.js,laravel,ardent,Jquery,Knockout.js,Laravel,Ardent,我正在尝试执行一个.ajax get来使用Laravel4中的Knockout/Jquery填充一个表。我使用的是Ardent,它会一直用下面的json响应进行响应 {"throwOnFind":false} 控制器: public function getData() { $roles = Role::select(array('roles.id', 'roles.name', 'roles.id as users', 'roles.created_at')); r

我正在尝试执行一个.ajax get来使用Laravel4中的Knockout/Jquery填充一个表。我使用的是Ardent,它会一直用下面的json响应进行响应

{"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());
JavaScript

    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());

我真的不知道从这里到哪里去。我认为问题可能出在Ardent中。

您误用了
select
方法,因为
Role::select(…)
只返回一个查询对象(),而不是结果本身

因此需要使用其他方法,如
get
来执行查询并获得实际结果

所以你需要写点东西liek:

$query = Role::select(array('roles.id',  ... , 'roles.created_at'));
$roles = $query->get();
return Response::json($roles, 200, array('Content-Type' => 'application/json'));

这么简单。此外,我还必须使用用于Knockout的映射插件来显示它。