Closed anuragd7 closed 6 years ago
The first thing I notice is showList
doesnt exist in your TS file.
@davecoffin - my apologies - I have edited my request with the correct code -
<FilterableListpicker #myfilter blur="dark" hintText="Type to filter..." [source]="showLessons" (canceled)="cancelFilterableList($event)" (itemTapped)="itemTapped($event)"></FilterableListpicker>
</GridLayout>
This source property is bound to showLessons in my original code and I made a mistake while pasting the code in the report. Any idea what might be going wrong? Thanks
The problem is the way you are setting up your showLessons array. Do this instead:
prepareLessons(lessonObject) {
const self = this;
let showLessonsArr = [];
for (const lesson of lessonObject) {
const lessonName = Object.keys(lesson);
const aLessonObject = { title: lessonName[0] };
showLessonsArr.push(aLessonObject);
}
this.showLessons = showLessonsArr;
console.log("number of items is " + this.showLessons.length);
}
try that.
Thanks @davecoffin for pointing out the error. Can confirm this works on both IOS and Android.
Make sure to check the demo app(s) for sample usage
Make sure to check the existing issues in this repository
If the demo apps cannot help and there is no issue for your problem, tell us about it
Please, ensure your title is less than 63 characters long and starts with a capital letter.
Which platform(s) does your issue occur on?
Please, provide the following version numbers that your issue occurs with:
Please, tell us how to recreate the issue in as much detail as possible.
Have setup the plugin as described in the ReadMe file. On triggering
showPicker()
the list of items shows correctly. However when I type in any string in the filterable listpicker the list of items becomes empty and nothing shows. Am not getting any error logs on the IOS (emulator) but on the android device I get the following error messageIs there any code involved?
TS File
import { registerElement } from "nativescript-angular/element-registry"; import { GradeSubjectService } from "../../services/grade-subject.service"; import { SearchModalComponent } from "../searchbar/searchModal.component";
registerElement( "FilterableListpicker", () => require("nativescript-filterable-listpicker").FilterableListpicker );
@Component({ moduleId: module.id, selector: "lessons", templateUrl: "./lessons.component.html" }) export class LessonsComponent implements OnInit, AfterViewInit { @Input() group: FormGroup; @Input() subjectSelected: any; @Input() gradeSelected: any;
@Input() searchGrades: any; @Input() searchSubjects: any;
@ViewChild("myfilter") myfilter: ElementRef;
@ViewChild("myGrid") myGrid: ElementRef; allLessons: any; showLessons: any[]; constructor(private gradeSubjectService: GradeSubjectService) { this.allLessons = this.gradeSubjectService.lessonsObject; this.showLessons = []; }
ngOnInit() { console.log( "subject selected in lessons is" + JSON.stringify(this.subjectSelected) ); }
ngAfterViewInit() { if (this.subjectSelected && this.gradeSelected) { for (let key in this.searchSubjects) { // skip loop if the property is from prototype if (!this.searchSubjects.hasOwnProperty(key)) continue; const subject = key; for (let key2 in this.allLessons[subject]) { const grade = key2; this.prepareLessons(this.allLessons[subject][grade]); } } // this.showLessons = this.allLessons[this.searchSubjects]; } }
cancelFilterableList() { console.log("canceled"); }
itemTapped(args) { console.log("selected lesson is " + args.selectedItem); }
showPicker() { this.myfilter.nativeElement.show(this.lessonGrid.nativeElement); }
prepareLessons(lessonObject) { const self = this; // const tempLessons = []; for (const lesson of lessonObject) { const lessonName = Object.keys(lesson); const aLessonObject = { title: lessonName[0] }; self.showLessons.push(aLessonObject); }
} }