我正在使用Ionic 2。
我有一些代码完美运行,然后在从6.3.0到6.3.1更新到cordova后,它再也无法工作了。我尝试降级回6.3.0。但它仍然无效。但是,我认为我的代码应该适用于6.3.1,所以我可能在我的代码中做了一些不正确的事情。
我有一个项目列表,然后当我更新列表时,DOM没有反映更新。
这里有两个问题:
search.html
...
<div id="pinButton"><button (click)="presentPopover()" secondary><ion-icon name="funnel"></ion-icon></button></div>
...
<ion-list>
<ion-item *ngFor="let item of employeeModels">
<ion-item>
<ion-row >
<ion-col><h2>{{item.firstName}}</h2></ion-col>
</ion-row>
</ion-item>
</ion-item>
</ion-list>
search.ts
...
@Component({
templateUrl: 'build/pages/search/search.html',
providers: [EmployeeService, UtilityService],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class SearchPage {
...
private employeeModel: EmployeeModel;
private employeeModels: EmployeeModel[] = [];
...
constructor(ref: ChangeDetectorRef, nav: NavController, employeeService: EmployeeService, utilityService: UtilityService, private navParams: NavParams, private popoverController: PopoverController) {
this.ref = ref;
this.nav = nav;
this.employeeService = employeeService;
this.utilityService = utilityService;
this.employeeModel = navParams.get('employeeModel');
console.log(this.employeeModel);
this.getEmployeeRange();
}
...
getEmployeeRange() {
console.log(this.employeeModel);
this.searchLoading = true;
var promise: Promise<EmployeeModel[]>;
promise = this.employeeService.getEmployeeRangeSearch(this.firstResult, this.MAX_RESULTS, this.getSubCategoryString())
promise.then((employeeModels: EmployeeModel[]) => {
for (var index = 0; index < employeeModels.length; index++) {
this.employeeModels.push(employeeModels[index]);
}
console.log(this.employeeModels.length);
this.searchLoading = false;
this.ref.markForCheck();
});
}
presentPopover(event: Event) {
console.log('presentPopover: '+this.employeeModel);
console.log(this.employeeModel);
let popover: Popover = this.popoverController.create(SearchPopOverPage, {employeeModel: this.employeeModel});
popover.present();
}
cat.ts
console.log(this.employeeModel);
this.nav.insert(0, SearchPage, {
employeeModel: this.employeeModel,
}).then(() => {
const index = this.nav.getActive().index;
this.nav.remove(index - 1);
});