如何使用具有角度数据的本地JSON对象 [英] How to use a local JSON object with angular-datatables
问题描述
我想这样做:
testdata = [{"id":"58",...}]; // local object
$('#test').dataTable({
"aaData": testdata,
"aoColumns": [
{ "mDataProp": "id" }
] });
与角度数据表模块。我已经尝试过:
with the angular-datatables module. I have tried this :
控制器
$scope.dtOptions = DTOptionsBuilder.fromSource('[{"id": 1}]')
.withDataProp('data')
.withBootstrap()
.withPaginationType('full_numbers');
$scope.dtColumns = [
DTColumnBuilder.newColumn('id').withTitle('ID')
];
查看
<table datatable="" dt-options="dtOptions" dt-columns="dtColumns" class="table table-striped table-bordered"></table>
但它根本不起作用,我收到此错误消息:
But it doesn't work at all, and I get this error message :
DataTables警告:table id = DataTables_Table_0 - Ajax错误。有关此错误的详细信息,请参阅 http://datatables.net/tn/7
此外,我不能使用任何Ajax选项从URL获取json数据,因为我的angularjs项目使用Express和Rest API,所以我没有获得401尝试使用/ api / data / getJsonData的GET / POST URL获取我的数据时出错。
Also, I can't use any Ajax options to get json data from an URL, because my angularjs project uses Express and the Rest API, so I get 401 not authorized error while trying to get my data with a GET/POST URL like "/api/data/getJsonData".
任何想法?谢谢。
推荐答案
您不能使用.fromSource,因为它总是会做一个ajaxUrl请求。但是您可以使用.fromFnPromise()替代。将您的JSON放入一个返回deferred.promise的函数。
You can't use .fromSource as it always will do an ajaxUrl request. But you can use .fromFnPromise() instead. Put your JSON into a function which returns an deferred.promise.
这篇关于如何使用具有角度数据的本地JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!