将嵌套对象从服务绑定到 angular 中的 ng2-smart table 2
bind nested object from service to ng2-smart table in angular 2
我是 angular 的新手 2
我有一个包含由服务驱动的 select 菜单的页面,当 select 一个项目时,我得到了 Full 对象,这个对象包含子对象,我需要将这个子对象绑定到 ng2-smart table ,我该怎么做
这是我的 type.html
<div class="widgets">
<div class="form-group">
<label for="exampleSelect1">Types</label>
<select [ngModel]="selectedObj" (ngModelChange)="onChangeObj($event)" name="sel3" class="form-control" id="exampleSelect1">
<option [ngValue]="obj" *ngFor="let obj of objects">{{ obj.objectName }}</option>
</select>
</div>
<div class="row">
<ba-card title="Types" baCardClass="with-scroll">
<ng2-smart-table class='form-control' [settings]="settings" [source]="source" (deleteConfirm)="onDeleteConfirm($event)"></ng2-smart-table>
</ba-card>
</div>
</div>
这是我的 type.component.ts
import {Component, ViewEncapsulation} from '@angular/core';
import { CustomerTypeService } from './customerType.service';
import { LocalDataSource } from 'ng2-smart-table';
import {TypeService} from './type.service';
@Component({
selector: 'basic-tables',
encapsulation: ViewEncapsulation.None,
styles: [require('./type.scss')],
template: require('./type.html'),
providers: [TypeService],
})
export class Type {
query: string = '';
settings = {
add: {
addButtonContent: '<i class="ion-ios-plus-outline"></i>',
createButtonContent: '<i class="ion-checkmark"></i>',
cancelButtonContent: '<i class="ion-close"></i>',
},
edit: {
editButtonContent: '<i class="ion-edit"></i>',
saveButtonContent: '<i class="ion-checkmark"></i>',
cancelButtonContent: '<i class="ion-close"></i>',
},
delete: {
deleteButtonContent: '<i class="ion-trash-a"></i>',
confirmDelete: true
},
columns: {
CustomerType: {
title: 'Type Name',
type: 'string'
}
}
};
source: LocalDataSource = new LocalDataSource();
public objects: Array<any> = new Array<any>();
public type: Array<any> = new Array<any>();
public id : number;
public objectsNum: number = 0;
constructor(protected _typeService: TypeService) {
this._typeService.getObject().subscribe((res) => {
this.objects = res;
this.objectsNum = (res) ? res.length : 0;
}, error => {
alert(error);
});
}
selectedObj = this.objects;
onChangeObj(newObj) {
console.log(newObj);
this.source.load(this.selectedObj)
}
onDeleteConfirm(event): void {
if (window.confirm('Are you sure you want to delete?')) {
event.confirm.resolve();
} else {
event.confirm.reject();
}
}
}
selected 对象结构类似于
object strucure
我需要在 Object 对象中获取类型列表以将其绑定到 table ,
提前致谢!
我在调用 onChangeObj 时发现它
onChangeObj(newObj) {
console.log(newObj);
this.source.load(newObj.type);
}
我是 angular 的新手 2 我有一个包含由服务驱动的 select 菜单的页面,当 select 一个项目时,我得到了 Full 对象,这个对象包含子对象,我需要将这个子对象绑定到 ng2-smart table ,我该怎么做
这是我的 type.html
<div class="widgets">
<div class="form-group">
<label for="exampleSelect1">Types</label>
<select [ngModel]="selectedObj" (ngModelChange)="onChangeObj($event)" name="sel3" class="form-control" id="exampleSelect1">
<option [ngValue]="obj" *ngFor="let obj of objects">{{ obj.objectName }}</option>
</select>
</div>
<div class="row">
<ba-card title="Types" baCardClass="with-scroll">
<ng2-smart-table class='form-control' [settings]="settings" [source]="source" (deleteConfirm)="onDeleteConfirm($event)"></ng2-smart-table>
</ba-card>
</div>
</div>
这是我的 type.component.ts
import {Component, ViewEncapsulation} from '@angular/core';
import { CustomerTypeService } from './customerType.service';
import { LocalDataSource } from 'ng2-smart-table';
import {TypeService} from './type.service';
@Component({
selector: 'basic-tables',
encapsulation: ViewEncapsulation.None,
styles: [require('./type.scss')],
template: require('./type.html'),
providers: [TypeService],
})
export class Type {
query: string = '';
settings = {
add: {
addButtonContent: '<i class="ion-ios-plus-outline"></i>',
createButtonContent: '<i class="ion-checkmark"></i>',
cancelButtonContent: '<i class="ion-close"></i>',
},
edit: {
editButtonContent: '<i class="ion-edit"></i>',
saveButtonContent: '<i class="ion-checkmark"></i>',
cancelButtonContent: '<i class="ion-close"></i>',
},
delete: {
deleteButtonContent: '<i class="ion-trash-a"></i>',
confirmDelete: true
},
columns: {
CustomerType: {
title: 'Type Name',
type: 'string'
}
}
};
source: LocalDataSource = new LocalDataSource();
public objects: Array<any> = new Array<any>();
public type: Array<any> = new Array<any>();
public id : number;
public objectsNum: number = 0;
constructor(protected _typeService: TypeService) {
this._typeService.getObject().subscribe((res) => {
this.objects = res;
this.objectsNum = (res) ? res.length : 0;
}, error => {
alert(error);
});
}
selectedObj = this.objects;
onChangeObj(newObj) {
console.log(newObj);
this.source.load(this.selectedObj)
}
onDeleteConfirm(event): void {
if (window.confirm('Are you sure you want to delete?')) {
event.confirm.resolve();
} else {
event.confirm.reject();
}
}
}
selected 对象结构类似于
object strucure
我需要在 Object 对象中获取类型列表以将其绑定到 table ,
提前致谢!
我在调用 onChangeObj 时发现它
onChangeObj(newObj) {
console.log(newObj);
this.source.load(newObj.type);
}