ProgressNS / nativescript-ui-feedback

This repository is used for customer feedback regarding Telerik UI for NativeScript. The issues system here is used by customers who want to submit their feature requests or vote for existing ones.
Other
115 stars 21 forks source link

RadListView multi template not working #1315

Closed kryptus36 closed 4 years ago

kryptus36 commented 4 years ago

Please, provide the details below:

Tell us about the problem

Please, ensure your title is less than 63 characters long and starts with a capital letter.

Which platform(s) does your issue occur on?

Both

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.

  1. Create a RadListView using multiple templates
  2. I can not get it to run the itemTemplateSelector

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

<lv:RadListView row="1" height="100%" items="{{ list }}" itemTemplateSelector="{{ potListTemplate }}">
<lv:RadListView.itemTemplate>
                                    <Label text="{{  template  }}" />
                                </lv:RadListView.itemTemplate>
                                <lv:RadListView.itemTemplates>
                                    <template key="mdate">
                                        <StackLayout orientation="vertical" style.backgroundColor="green">
                                            <Label text="{{ date }}" class='date' />
                                        </StackLayout>
                                    </template>
                                    <template key="promotion">
                                        <StackLayout class='promotion'>
                                            <Label text="{{  title  }}" class='title' textWrap='true' />
                                            <Label text="{{  description  }}" class='description' textWrap='true' />
                                        </StackLayout>
                                    </template>
                                </lv:RadListView.itemTemplates>

                            </lv:RadListView>

In my js file I have a simple function inside my view model object (which never fires and the default template is always used and the label shows "mdate"):

potListTemplate: function(item, index, items) {
      console.log('template', item);
      return item.template;
    }

if I change itemTemplateSelector="mdate" the app crashes .

kryptus36 commented 4 years ago

scope issue. I needed to use $parents in my binding

louislamlam commented 4 years ago

scope issue. I needed to use $parents in my binding

I am using nativescript-vue and experience the same issue of using multiple conditional templates , could you share me more information of your solution? Thanks.

kryptus36 commented 4 years ago

I am using my listview inside of a nativescript-carousel. So I needed to change the above code to


<lv:RadListView row="1" height="100%" items="{{ list }}" itemTemplateSelector="{{ $parents['Carousel'].potListTemplate }}">```

I found this helpful:
https://docs.nativescript.org/core-concepts/data-binding#binding-to-a-parent-binding-context