jqgrid - 使用http get以角度6将数据加载到网格
问题描述
http.get
我正在尝试使用角度 6将以下示例数据加载到 jqgrid(free) 。
[{"maker":"Toyota", "model":"Celica"},{ "maker": "Chrysler", "model":"Mondeo"}]
模型类
export class Model{
maker : string
model : string
}
零件:
...
@Component({...})
export class SampleComponent implements OnInit {
private _sampleService;
columnModel : any[];
models : Model[];
constructor(_sampleService : SampleService) {
this._sampleService = _sampleService;
}
ngOnInit() {
this.columnModel = [{ name: "maker" },{ name: "model" }]
this.models = this._sampleService.getModelList().subscribe(models => this.models = models);
}
ngAfterViewInit() {
(<any>jQuery("#grid")).jqGrid({
colModel: this.columnModel,
data: this.models
});
}
}
服务:
....
@Injectable()
export class SampleService{
constructor(private http : HttpClient){}
getModelList():Observable<Model[]>{
return this.http.get<Model[]>
("http://localhost:8090/myapp/getModel");
}
}
如果我执行以下操作,我可以在控制台中看到数据。
this.http.get("http://localhost:8090/ducksoup/getModel")
.subscribe(data => {console.log(data)})
但是,它不是在网格中渲染。有什么帮助吗?
解决方案
您可以在获取记录后立即在 OnInit 方法中编写 jqxGrid 绑定代码,它将在 datagrid 上显示您的数据
推荐阅读
- python - 在 pytest 函数中使用 subprocess.run() 会导致任何测试问题吗?
- python - Postgres“CREATE TABLE AS(SELECT ...)”卡住了
- powershell - 无法使用空组捕获工作站详细信息
- flutter - 检测设备是否会在 Flutter 中显示软键盘
- reactjs - 反应打字稿和孩子
- git - 为了防止性能问题,省略了 82 个额外的提交。GitLab
- firebase - Firebase OnDisconnect 事件
- r - R:我的数据框有 1 列和多行,有没有办法计算某些行子集的平均值?
- python - 在机器学习 python 中使用模型进行预测
- sql - 通过连接视图和表实现物化视图