angular - Angular DataTables - 来自本地存储的 ajax 调用
问题描述
我正在寻找一种方法来对已经存储了 json 对象的本地存储进行 ajax 调用,以便可以将其加载到表中。
loadDataTable() {
this.jsonService.getJson().subscribe(response => {
this.dataToRead = response.data;
});
this.dtOptions = {
ajax: this.dataToRead,
columns: [{
title: 'ID',
data: 'id'
},
{
title: 'Name',
data: 'name'
},
{
title: 'Age',
data: 'age',
},
{
title: 'Address',
data: 'address'
}],
rowCallback: (row: Node, data: any[] | Object, index: number) => {
const self = this;
$('td', row).unbind('click');
$('td', row).bind('click', () => {
self.viewFarmDetails(data);
});
return row;
}
};
解决方案
如果数据在本地存储中,您可以读取它。
导入组件中的任何实用程序库(例如 ngx-webstorage)
import { LocalStorageService } from 'ngx-webstorage';
将其添加到您的构造函数
constructor(private $localStorage: LocalStorageService) {
}
然后在需要时从 localStorage 中读取
this.$localStorage.retrieve('my-data-in-storage')
用您在存储中存储该数据的密钥替换“my-data-in-storage”!
希望这会有所帮助!
推荐阅读
- c++ - 如何编写一个算法来找出特定单词出现在哪些行中(我正在使用 std::map)
- r - 如何在R中输入时间序列数据?
- html - CSS:translateY之间的空白
- compiler-errors - 我的程序不工作。Main 没有返回值
- php - Braintree PHP 所需版本冲突
- python - PyGObject的MSYS2 python解释器和标准python解释器之间的区别?
- python-3.x - 如何加载经过训练的自动编码器 (Keras)、获取编码器部分并将其冻结?
- datagrid - react-admin 列表视图中的自定义行
- python - 为什么我们需要在调用另一个类函数时将 self 作为参数
- java - 从 cvs 文件中将多个值放入数组中