1

I'm using a modal to show a listView and I want to pass the list into the modal as an array. I call the modal, like so:

this.$showModal(Picker, { props: { list: [

  { name: "Item 1" },
  { name: "Item 2" },
  { name: "Item 3" }

]}});

The modal loads fine, and I can see the props in the modal when I console.log

created: function(){
  console.log(this.list);
}, 

However, I can't access the props in the template or loop over them.

 <ListView for="item in listOfItems">
   <v-template>
     <Label :text="item.name" class="listItem" />
   </v-template>
 </ListView>

I have also tried:

<ListView :for="item in $props.list">

My full code for the modal component is below:

<template>
  <Page>

     <ListView for="item in listOfItems">
       <v-template>
        <Label :text="item.name" class="listItem" />
       </v-template>
     </ListView>

  </Page>
</template>

<script>

  export default {

    props: ["list"],

    created: function(){
      console.log(this.list);
    },

    data(){
      return {
        listOfItems: this.list
      }
    }
  }

</script>

What am I doing wrong?

3 Answers 3

1

Change <ListView for="item in listOfItems"> to <ListView for="item in list">

Sign up to request clarification or add additional context in comments.

3 Comments

Doesn't work :( For some reason the props don't seem to be accessible from the template. I've also tried passing in a single value and add it to Label's text, but it just can't seem to access it.
Nope, it just loads a blank modal.
hm. Can you provide a working jsFiddle like link (it would very helpful to debug)?
0

Don’t know why, but when I changed the data() return { so that the variable names are the same, {animals: animals, vegetables: vegetables } it worked.

Didn’t have to do this for strings or integers, just objects.

Comments

0

<ListView for="item in $props.list">

Remove colon?

I'm taking care of removing unnecessary : of head of for and refering to $props property when coding with NativeScript-Vue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.