如何使用带角的DataTable本地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 :
数据表警告:表ID = DataTables_Table_0 - 阿贾克斯错误。有关此错误的详细信息,请参阅 http://datatables.net/tn/7
DataTables warning: table id=DataTables_Table_0 - Ajax error. For more information about this error, please see http://datatables.net/tn/7
另外,我不能使用任何Ajax的选项来从URL获取JSON数据,因为我的angularjs项目使用防爆preSS和REST API,所以我得到401未授权错误,而试图让我的数据与一个GET / POST网址,如/ API /数据/ getJsonData。
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.
这篇关于如何使用带角的DataTable本地JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!