javascriptnativescriptradlistview

How to use set javascript variable value for use in Nativescript XML


i'm using radlistview to load data from my remote server, i use if statement for some of the elements in the radlistview.

horizontalAlignment="{{ (seller != myemail) ? 'right' : 'left' }}

The issue i'm having is, seller is loaded from the remote server, while the value of myemail was set using viewModel.set("myemail", "example"); . but this doesn't work, it seems only the data loaded from the server can be used in the radlistview. is there a way i can also set values in my viewModel and use it in my xml

this is my radlistview code

 <lv:RadListView style="height:100%;" row="1" items="{{ dataItems }}" loaded="onListLoaded" loadOnDemandMode="Auto" loadMoreDataRequested="{{ onLoadMoreItemsRequested }}" itemLoading="{{ onItemLoading }}" class="list-group"> 
                            <lv:RadListView.listViewLayout>
                                <lv:ListViewLinearLayout scrollDirection="Vertical" dynamicItemSize="false" itemInsertAnimation="Scale" itemDeleteAnimation="Scale"/>
                            </lv:RadListView.listViewLayout>
                        <lv:RadListView.itemTemplate>
                            <StackLayout>
                            <StackLayout class="message-item" style="width:75%;" horizontalAlignment="{{ (seller != myemail) ? 'right' : 'left' }}">
                                <StackLayout class="message-block" verticalAlignment="top" horizontalAlignment="{{ (seller != sender) ? 'right' : 'left' }}"  borderTopRightRadius="{{ (seller !== sender) ? '0' : '10' }}" borderTopLeftRadius="{{ (seller != sender) ? '10' : '0' }}" style="{{ (seller != sender) ? 'background-color:#b9d4c8' : 'background-color:#cef5e9' }}">
                                    <Label text="{{ (seller != myemail) ? 'You' : sender }}" verticalAlignment="top" class="message-autor"></Label>
                                    <Label text="{{ message }}" textWrap="true" verticalAlignment="top" class="message-body"></Label>
                                </StackLayout>
                            </StackLayout>
                            </StackLayout>
                        </lv:RadListView.itemTemplate>
                    </lv:RadListView>

Thanks in advance, let me know if you need more info


Solution

  • The binding content for each item in a RadListView is the corresponding array entry, as you've discovered. To reference the page's binding context, you can use $parents['Page'].myemail.