本帖最后由 nikankind 于 2017-9-8 09:49 编辑
Angular2中使用FlexGrid控件显示报表,用Rxjs在初始化时请求服务端数据。希望点击链接能立即看到数据内容,但现在需要点一下表头才可以,请问如何解决?谢谢
部分代码如下:
前端模板dlv-bid.component.html:
- <wj-flex-grid [allowDragging]="'Both'" [itemsSource]="treeData" style="height : 360px" [isReadOnly]="true">
- <wj-flex-grid-column [header]="'发货单号'" [binding]="'dlvBilNo'" [width]="'*'"></wj-flex-grid-column>
- <wj-flex-grid-column [header]="'出发地'" [binding]="'stLoc'" [width]="'*'"></wj-flex-grid-column>
- <wj-flex-grid-column [header]="'目的地'" [binding]="'destLoc'" [width]="'*'"></wj-flex-grid-column>
- <wj-flex-grid-column [header]="'发货时间'" [binding]="'elstDlvTim'" [width]="'*'"></wj-flex-grid-column>
- <wj-flex-grid-column [header]="'到货时间'" [binding]="'elstArvTim'" [width]="'*'"></wj-flex-grid-column>
- </wj-flex-grid>
复制代码 组件文件dlv-bid.component.ts:
- @Component({
- selector: 'app-dlv-bid',
- templateUrl: './dlv-bid.component.html',
- styleUrls: ['./dlv-bid.component.css']
- })
- export class DlvBidComponent implements OnInit {
- dlvBidService: DlvBidService;
- treeData: wjcCore.CollectionView;
- constructor(@Inject(DlvBidService) dlvBidService: DlvBidService) {
- this.dlvBidService = dlvBidService;
- }
- ngOnInit() {
- this.dlvBidService.GetPreDlvBids();
- this.treeData = new wjcCore.CollectionView(this.dlvBidService.tree);
- }
复制代码 数据服务dlv-bid.component.service.ts:
- @Injectable()
- export class DlvBidService {
- public tree = [];
- public GetPreDlvBids() {
- return this.http
- .get(`${this.dlvBidURL}getDlvBids?token=${localStorage.getItem('access_token')}`)
- .map((res: Response) => {
- const rst = this.extractData(res);
- console.log(rst);
- if (rst.vali === false) {
- alert('登录错误,请重新登录');
- return;
- } else if ( rst.succ === false) {
- alert('信息提取错误');
- return;
- }
- this.getTreeData(rst);
- })
- .subscribe();
- }
- getTreeData(src: any) {
- let tmp: string;
- let key: string;
- let tmpObj: any;
- let i: Number = 0;
- tmp = JSON.stringify(src);
- tmpObj = JSON.parse(tmp);
- delete tmpObj.succ;
- delete tmpObj.vali;
- for ( key in tmpObj) {
- // console.log(`\'${key}\'`);
- this.tree.push(tmpObj[`${key}`]);
- }
- }
- }
复制代码
|
|