Nativescript Vue ListView - Expected Array, got Object












0















I'm trying to use the ListView element like this:



<ListView for="reservacion in reservaciones" @itemTap="onItemTap">
<v-template>
<Label :text="reservacion.fecha_reservacion" />
</v-template>
</ListView>


But I'm getting the following error:




[Vue warn]: Invalid prop: type check failed for prop "items". Expected Array, got Object.




In my axios call I bind this.reservaciones = response.data, where data is an array of objects:



[{
"id":25,
"folio":"181019165089",
"jugador_id":3,
"fecha_reservacion":"2018-10-19",
"hora_reservacion":"07:00:00",
"hoyo":1,
"user_id":3,
"status":0,
"tipo_reservacion":3,
"created_at":"2018-10-19 16:50:17",
"updated_at":"2018-10-22 10:49:26"
},{
"id":32,
"folio":"181019170560",
"jugador_id":3,
"fecha_reservacion":"2018-10-19",
"hora_reservacion":"07:10:00",
"hoyo":10,
"user_id":3,
"status":0,
"tipo_reservacion":3,
"created_at":"2018-10-19 17:05:28",
"updated_at":"2018-10-22 10:49:57"
}]


How can I "transform" the Array of Objects in the response into an Array of Arrays? So that I can bind it to the List View.










share|improve this question





























    0















    I'm trying to use the ListView element like this:



    <ListView for="reservacion in reservaciones" @itemTap="onItemTap">
    <v-template>
    <Label :text="reservacion.fecha_reservacion" />
    </v-template>
    </ListView>


    But I'm getting the following error:




    [Vue warn]: Invalid prop: type check failed for prop "items". Expected Array, got Object.




    In my axios call I bind this.reservaciones = response.data, where data is an array of objects:



    [{
    "id":25,
    "folio":"181019165089",
    "jugador_id":3,
    "fecha_reservacion":"2018-10-19",
    "hora_reservacion":"07:00:00",
    "hoyo":1,
    "user_id":3,
    "status":0,
    "tipo_reservacion":3,
    "created_at":"2018-10-19 16:50:17",
    "updated_at":"2018-10-22 10:49:26"
    },{
    "id":32,
    "folio":"181019170560",
    "jugador_id":3,
    "fecha_reservacion":"2018-10-19",
    "hora_reservacion":"07:10:00",
    "hoyo":10,
    "user_id":3,
    "status":0,
    "tipo_reservacion":3,
    "created_at":"2018-10-19 17:05:28",
    "updated_at":"2018-10-22 10:49:57"
    }]


    How can I "transform" the Array of Objects in the response into an Array of Arrays? So that I can bind it to the List View.










    share|improve this question



























      0












      0








      0








      I'm trying to use the ListView element like this:



      <ListView for="reservacion in reservaciones" @itemTap="onItemTap">
      <v-template>
      <Label :text="reservacion.fecha_reservacion" />
      </v-template>
      </ListView>


      But I'm getting the following error:




      [Vue warn]: Invalid prop: type check failed for prop "items". Expected Array, got Object.




      In my axios call I bind this.reservaciones = response.data, where data is an array of objects:



      [{
      "id":25,
      "folio":"181019165089",
      "jugador_id":3,
      "fecha_reservacion":"2018-10-19",
      "hora_reservacion":"07:00:00",
      "hoyo":1,
      "user_id":3,
      "status":0,
      "tipo_reservacion":3,
      "created_at":"2018-10-19 16:50:17",
      "updated_at":"2018-10-22 10:49:26"
      },{
      "id":32,
      "folio":"181019170560",
      "jugador_id":3,
      "fecha_reservacion":"2018-10-19",
      "hora_reservacion":"07:10:00",
      "hoyo":10,
      "user_id":3,
      "status":0,
      "tipo_reservacion":3,
      "created_at":"2018-10-19 17:05:28",
      "updated_at":"2018-10-22 10:49:57"
      }]


      How can I "transform" the Array of Objects in the response into an Array of Arrays? So that I can bind it to the List View.










      share|improve this question
















      I'm trying to use the ListView element like this:



      <ListView for="reservacion in reservaciones" @itemTap="onItemTap">
      <v-template>
      <Label :text="reservacion.fecha_reservacion" />
      </v-template>
      </ListView>


      But I'm getting the following error:




      [Vue warn]: Invalid prop: type check failed for prop "items". Expected Array, got Object.




      In my axios call I bind this.reservaciones = response.data, where data is an array of objects:



      [{
      "id":25,
      "folio":"181019165089",
      "jugador_id":3,
      "fecha_reservacion":"2018-10-19",
      "hora_reservacion":"07:00:00",
      "hoyo":1,
      "user_id":3,
      "status":0,
      "tipo_reservacion":3,
      "created_at":"2018-10-19 16:50:17",
      "updated_at":"2018-10-22 10:49:26"
      },{
      "id":32,
      "folio":"181019170560",
      "jugador_id":3,
      "fecha_reservacion":"2018-10-19",
      "hora_reservacion":"07:10:00",
      "hoyo":10,
      "user_id":3,
      "status":0,
      "tipo_reservacion":3,
      "created_at":"2018-10-19 17:05:28",
      "updated_at":"2018-10-22 10:49:57"
      }]


      How can I "transform" the Array of Objects in the response into an Array of Arrays? So that I can bind it to the List View.







      listview vue.js nativescript






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 6:15









      kit

      1,1063716




      1,1063716










      asked Nov 22 '18 at 2:06









      Jk33Jk33

      172114




      172114
























          1 Answer
          1






          active

          oldest

          votes


















          1














          This is sample Vue File which binds ListView in NativeScript Vue File using static list array data.



          <template>
          <Page class="page">
          <ActionBar class="action-bar">
          <Label class="action-bar-title" text="Home"></Label>
          </ActionBar>


          <ListView for="item in listOfItems" >
          <v-template>
          <!-- Shows the list item label in the default color and style. -->
          <GridLayout rows="auto" columns="*,*">
          <Label :text="item.text" col="0" row="0"></Label>
          <Label :text="item.name" col="1" row="0"></Label>
          </GridLayout>
          </v-template>
          </ListView>

          </Page>
          </template>
          <script>
          const listItems = [ {text:"One", name:"FirstElement"}, {text:"two", name:"SecondElement"}
          ];
          export default{

          computed :{
          listOfItems()
          {
          return listItems;
          }
          },

          };
          </script>
          <style lang="scss" scoped>
          // Start custom common variables
          @import '../../_app-variables.scss';

          // End custom common variables

          // Custom styles
          .fa {
          color: $accent-dark;
          }

          .info {
          font-size: 20;
          }
          </style>


          When you get response from axios you need to convert it to JSON some thing like below.



          var listOfItems;  // <--- wanted to view this in console, so made it global
          // NOTE: drop multiple map markers, use an array of marker objects
          axios.get('url')
          .then(function (response) {
          listOfItems = JSON.parse(response.data);
          })
          .catch(function (error) {
          console.log(error);
          });


          This sample is tested in Android Emulator.






          share|improve this answer


























          • Seems like I had my response a bit messed up, the array was actually in response.data.data, but trying with a static list pointed me in the right direction so I'll mark this as correct. I did NOT need to parse it btw. Thank you.

            – Jk33
            Nov 22 '18 at 15:27













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422925%2fnativescript-vue-listview-expected-array-got-object%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          This is sample Vue File which binds ListView in NativeScript Vue File using static list array data.



          <template>
          <Page class="page">
          <ActionBar class="action-bar">
          <Label class="action-bar-title" text="Home"></Label>
          </ActionBar>


          <ListView for="item in listOfItems" >
          <v-template>
          <!-- Shows the list item label in the default color and style. -->
          <GridLayout rows="auto" columns="*,*">
          <Label :text="item.text" col="0" row="0"></Label>
          <Label :text="item.name" col="1" row="0"></Label>
          </GridLayout>
          </v-template>
          </ListView>

          </Page>
          </template>
          <script>
          const listItems = [ {text:"One", name:"FirstElement"}, {text:"two", name:"SecondElement"}
          ];
          export default{

          computed :{
          listOfItems()
          {
          return listItems;
          }
          },

          };
          </script>
          <style lang="scss" scoped>
          // Start custom common variables
          @import '../../_app-variables.scss';

          // End custom common variables

          // Custom styles
          .fa {
          color: $accent-dark;
          }

          .info {
          font-size: 20;
          }
          </style>


          When you get response from axios you need to convert it to JSON some thing like below.



          var listOfItems;  // <--- wanted to view this in console, so made it global
          // NOTE: drop multiple map markers, use an array of marker objects
          axios.get('url')
          .then(function (response) {
          listOfItems = JSON.parse(response.data);
          })
          .catch(function (error) {
          console.log(error);
          });


          This sample is tested in Android Emulator.






          share|improve this answer


























          • Seems like I had my response a bit messed up, the array was actually in response.data.data, but trying with a static list pointed me in the right direction so I'll mark this as correct. I did NOT need to parse it btw. Thank you.

            – Jk33
            Nov 22 '18 at 15:27


















          1














          This is sample Vue File which binds ListView in NativeScript Vue File using static list array data.



          <template>
          <Page class="page">
          <ActionBar class="action-bar">
          <Label class="action-bar-title" text="Home"></Label>
          </ActionBar>


          <ListView for="item in listOfItems" >
          <v-template>
          <!-- Shows the list item label in the default color and style. -->
          <GridLayout rows="auto" columns="*,*">
          <Label :text="item.text" col="0" row="0"></Label>
          <Label :text="item.name" col="1" row="0"></Label>
          </GridLayout>
          </v-template>
          </ListView>

          </Page>
          </template>
          <script>
          const listItems = [ {text:"One", name:"FirstElement"}, {text:"two", name:"SecondElement"}
          ];
          export default{

          computed :{
          listOfItems()
          {
          return listItems;
          }
          },

          };
          </script>
          <style lang="scss" scoped>
          // Start custom common variables
          @import '../../_app-variables.scss';

          // End custom common variables

          // Custom styles
          .fa {
          color: $accent-dark;
          }

          .info {
          font-size: 20;
          }
          </style>


          When you get response from axios you need to convert it to JSON some thing like below.



          var listOfItems;  // <--- wanted to view this in console, so made it global
          // NOTE: drop multiple map markers, use an array of marker objects
          axios.get('url')
          .then(function (response) {
          listOfItems = JSON.parse(response.data);
          })
          .catch(function (error) {
          console.log(error);
          });


          This sample is tested in Android Emulator.






          share|improve this answer


























          • Seems like I had my response a bit messed up, the array was actually in response.data.data, but trying with a static list pointed me in the right direction so I'll mark this as correct. I did NOT need to parse it btw. Thank you.

            – Jk33
            Nov 22 '18 at 15:27
















          1












          1








          1







          This is sample Vue File which binds ListView in NativeScript Vue File using static list array data.



          <template>
          <Page class="page">
          <ActionBar class="action-bar">
          <Label class="action-bar-title" text="Home"></Label>
          </ActionBar>


          <ListView for="item in listOfItems" >
          <v-template>
          <!-- Shows the list item label in the default color and style. -->
          <GridLayout rows="auto" columns="*,*">
          <Label :text="item.text" col="0" row="0"></Label>
          <Label :text="item.name" col="1" row="0"></Label>
          </GridLayout>
          </v-template>
          </ListView>

          </Page>
          </template>
          <script>
          const listItems = [ {text:"One", name:"FirstElement"}, {text:"two", name:"SecondElement"}
          ];
          export default{

          computed :{
          listOfItems()
          {
          return listItems;
          }
          },

          };
          </script>
          <style lang="scss" scoped>
          // Start custom common variables
          @import '../../_app-variables.scss';

          // End custom common variables

          // Custom styles
          .fa {
          color: $accent-dark;
          }

          .info {
          font-size: 20;
          }
          </style>


          When you get response from axios you need to convert it to JSON some thing like below.



          var listOfItems;  // <--- wanted to view this in console, so made it global
          // NOTE: drop multiple map markers, use an array of marker objects
          axios.get('url')
          .then(function (response) {
          listOfItems = JSON.parse(response.data);
          })
          .catch(function (error) {
          console.log(error);
          });


          This sample is tested in Android Emulator.






          share|improve this answer















          This is sample Vue File which binds ListView in NativeScript Vue File using static list array data.



          <template>
          <Page class="page">
          <ActionBar class="action-bar">
          <Label class="action-bar-title" text="Home"></Label>
          </ActionBar>


          <ListView for="item in listOfItems" >
          <v-template>
          <!-- Shows the list item label in the default color and style. -->
          <GridLayout rows="auto" columns="*,*">
          <Label :text="item.text" col="0" row="0"></Label>
          <Label :text="item.name" col="1" row="0"></Label>
          </GridLayout>
          </v-template>
          </ListView>

          </Page>
          </template>
          <script>
          const listItems = [ {text:"One", name:"FirstElement"}, {text:"two", name:"SecondElement"}
          ];
          export default{

          computed :{
          listOfItems()
          {
          return listItems;
          }
          },

          };
          </script>
          <style lang="scss" scoped>
          // Start custom common variables
          @import '../../_app-variables.scss';

          // End custom common variables

          // Custom styles
          .fa {
          color: $accent-dark;
          }

          .info {
          font-size: 20;
          }
          </style>


          When you get response from axios you need to convert it to JSON some thing like below.



          var listOfItems;  // <--- wanted to view this in console, so made it global
          // NOTE: drop multiple map markers, use an array of marker objects
          axios.get('url')
          .then(function (response) {
          listOfItems = JSON.parse(response.data);
          })
          .catch(function (error) {
          console.log(error);
          });


          This sample is tested in Android Emulator.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 '18 at 4:03

























          answered Nov 22 '18 at 3:56









          BaskarBaskar

          40637




          40637













          • Seems like I had my response a bit messed up, the array was actually in response.data.data, but trying with a static list pointed me in the right direction so I'll mark this as correct. I did NOT need to parse it btw. Thank you.

            – Jk33
            Nov 22 '18 at 15:27





















          • Seems like I had my response a bit messed up, the array was actually in response.data.data, but trying with a static list pointed me in the right direction so I'll mark this as correct. I did NOT need to parse it btw. Thank you.

            – Jk33
            Nov 22 '18 at 15:27



















          Seems like I had my response a bit messed up, the array was actually in response.data.data, but trying with a static list pointed me in the right direction so I'll mark this as correct. I did NOT need to parse it btw. Thank you.

          – Jk33
          Nov 22 '18 at 15:27







          Seems like I had my response a bit messed up, the array was actually in response.data.data, but trying with a static list pointed me in the right direction so I'll mark this as correct. I did NOT need to parse it btw. Thank you.

          – Jk33
          Nov 22 '18 at 15:27




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422925%2fnativescript-vue-listview-expected-array-got-object%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          To store a contact into the json file from server.js file using a class in NodeJS

          Redirect URL with Chrome Remote Debugging Android Devices

          Dieringhausen