moayadnajd / nativescript-filter-select

A NativeScript plugin to provide an listview widget to select AND filter items
http://codeobia.com
Other
37 stars 19 forks source link

Cannot set selected value #35

Closed bachras closed 6 years ago

bachras commented 6 years ago

Hi,

thank you for brilliant plugin, everthing works as expected, but I am strugling to set previously selected value. I followed examples but I am keep getting this error:

System.err: com.tns.NativeScriptException: 
System.err: Calling js method getView failed
System.err: TypeError: self.selected_items.filter is not a function
System.err: File: "file:///data/data/org.nativescript.app1/files/app/tns_modules/nativescript-filter-select/filter-select.common.js, line: 444, column: 47
System.err: StackTrace: 
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.app1/files/app/tns_modules/nativescript-filter-select/filter-select.common.js', line: 444, column: 48
System.err:     Frame: function:'Observable.notify', file:'file:///data/data/org.nativescript.app1/files/app/tns_modules/tns-core-modules/data/observable/observable.js', line: 103, column: 23
System.err:     Frame: function:'ListViewAdapter.getView', file:'file:///data/data/org.nativescript.app1/files/app/tns_modules/tns-core-modules/ui/list-view/list-view.js', line: 242, column: 24
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:957)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:941)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:933)
System.err:     at com.tns.gen.android.widget.BaseAdapter_frnal_ts_helpers_l58_c38__ListViewAdapter.getView(BaseAdapter_frnal_ts_helpers_l58_c38__ListViewAdapter.java:47)
System.err:     at android.widget.AbsListView.obtainView(AbsListView.java:2347)
System.err:     at android.widget.ListView.makeAndAddView(ListView.java:1864)
System.err:     at android.widget.ListView.fillDown(ListView.java:698)
System.err:     at android.widget.ListView.fillFromTop(ListView.java:759)
System.err:     at android.widget.ListView.layoutChildren(ListView.java:1673)
System.err:     at android.widget.AbsListView.onLayout(AbsListView.java:2151)
System.err:     at android.view.View.layout(View.java:15671)
System.err:     at android.view.ViewGroup.layout(ViewGroup.java:5038)
System.err:     at org.nativescript.widgets.CommonLayoutParams.layoutChild(CommonLayoutParams.java:222)
System.err:     at org.nativescript.widgets.StackLayout.layoutVertical(StackLayout.java:169)
System.err:     at org.nativescript.widgets.StackLayout.onLayout(StackLayout.java:123)
System.err:     at android.view.View.layout(View.java:15671)
System.err:     at android.view.ViewGroup.layout(ViewGroup.java:5038)
System.err:     at org.nativescript.widgets.CommonLayoutParams.layoutChild(CommonLayoutParams.java:222)
System.err:     at org.nativescript.widgets.GridLayout.onLayout(GridLayout.java:353)
System.err:     at android.view.View.layout(View.java:15671)
System.err:     at android.view.ViewGroup.layout(ViewGroup.java:5038)
System.err:     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
System.err:     at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
System.err:     at android.view.View.layout(View.java:15671)
System.err:     at android.view.ViewGroup.layout(ViewGroup.java:5038)
System.err:     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
System.err:     at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
System.err:     at android.view.View.layout(View.java:15671)
System.err:     at android.view.ViewGroup.layout(ViewGroup.java:5038)
System.err:     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
System.err:     at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
System.err:     at android.view.View.layout(View.java:15671)
System.err:     at android.view.ViewGroup.layout(ViewGroup.java:5038)
System.err:     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
System.err:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
System.err:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
System.err:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
System.err:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
System.err:     at android.view.Choreographer.doCallbacks(Choreographer.java:580)
System.err:     at android.view.Choreographer.doFrame(Choreographer.java:550)
System.err:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
System.err:     at android.os.Handler.handleCallback(Handler.java:739)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
System.err:     at android.os.Looper.loop(Looper.java:135)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:5254)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

I created playground example to replicate the problem: https://play.nativescript.org/?template=play-ng&id=lx6dNk&v=3

Maybe I missed something. Any help/advice is appreciated. Thank you

moayadnajd commented 6 years ago

@bachras thanks for using my plugin about the issue you made i think you mixed the binding with the vanilla way you can see below i made some changes https://play.nativescript.org/?template=play-ng&id=lx6dNk&v=6

the right way of binding is this

    <FilterSelect render="label" height="100%" [selected]="selected" [items]="countries" (change)="selectCountry($event)" hint="Please select some items" modal_title="item"
         search_param="name" primary_key="code">
        </FilterSelect>

but you was doing it with {{ }} and this way is not working with angular

<FilterSelect height="100%" render="label" items="{{countries}}" (change)="selectCountry($event)" 
        search_param="name" primary_key="code"
         selected="{{selected}}">
        </FilterSelect>

thanks and don't forget to start the plugin 👍 😃

sudhakarmapol commented 4 years ago

Thanks for your solution. But while am trying to set the value from the constructor or the NgOninit. the value cannot be bind. please help to resolve this issue. Also how to set a value pro-grammatically in angular.

https://play.nativescript.org/?template=play-ng&id=L1ulE5&v=2