Javascript 将值传递给扩展插件ng2智能表
我已经检查了文档和分页实现的源代码(AdvancedExampleServer.component.ts) 并发现它使用的ServerDataSource只通过HTTP GET实现了分页(_sort、_limit、_page等参数在URL中公开)。。。。。由于我当前的项目需要使用POST将前端参数发送到后端Restful API 使用extends to HTTP post调用实现,我不知道如何在分页请求中添加额外的参数。我需要将请求\u服务器传递到extendsplugin.tsJavascript 将值传递给扩展插件ng2智能表,javascript,angular,typescript,ng2-smart-table,Javascript,Angular,Typescript,Ng2 Smart Table,我已经检查了文档和分页实现的源代码(AdvancedExampleServer.component.ts) 并发现它使用的ServerDataSource只通过HTTP GET实现了分页(_sort、_limit、_page等参数在URL中公开)。。。。。由于我当前的项目需要使用POST将前端参数发送到后端Restful API 使用extends to HTTP post调用实现,我不知道如何在分页请求中添加额外的参数。我需要将请求\u服务器传递到extendsplugin.ts import
import { Observable } from 'rxjs/internal/Observable';
import { ServerDataSource } from 'ng2-smart-table';
export class PostServerDataSource extends ServerDataSource {
protected requestElements(): Observable<any> {
let httpParams = this.createRequesParams();
return this.http.post(this.conf.endPoint, request_server, { observe: 'response' });
}
}
有两种方法可以处理它, 一种方法是在查询字符串中附加参数,然后像
this.service.apiURL + 'swift/pagination?param1=p¶m2=q'
另一种方法是在requestElements和swiftListTable函数中处理它,如下所示
swiftListTable() {
const request_server = {
"userType": this.currentUser.role,
"authName": this.currentUser.username
}
this.source = new PostServerDataSource(http,
{ endPoint: url, dataKey: 'content', pagerLimitKey:'_limit'}, request_server);
导出类PostServerDataSource扩展ServerDataSource{
参数:任何;
构造函数(http:HttpClient,config:any,params?:any){
超级(http,config);
this.params=params;
}
受保护的requestElements():可观察{
让httpParams=this.createRequesParams();
if(this.params){
让keys=Object.keys(this.params);
key.forEach((key)=>{
httpParams=httpParams.set(key,this.params[key]);
});
}
返回this.http.post(this.conf.endPoint,httpParams,{observe:'response'});
}
}
swiftListTable() {
const request_server = {
"userType": this.currentUser.role,
"authName": this.currentUser.username
}
this.source = new PostServerDataSource(http,
{ endPoint: url, dataKey: 'content', pagerLimitKey:'_limit'}, request_server);
export class PostServerDataSource extends ServerDataSource {
params: any;
constructor(http: HttpClient, config: any, params?: any) {
super(http, config);
this.params = params;
}
protected requestElements(): Observable<any> {
let httpParams = this.createRequesParams();
if (this.params) {
let keys = Object.keys(this.params);
keys.forEach((key) => {
httpParams = httpParams.set(key, this.params[key]);
});
}
return this.http.post(this.conf.endPoint, httpParams, { observe: 'response' });
}
}