Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 如何循环vue js中的JSON对象_Laravel_Vue.js_Nested - Fatal编程技术网

Laravel 如何循环vue js中的JSON对象

Laravel 如何循环vue js中的JSON对象,laravel,vue.js,nested,Laravel,Vue.js,Nested,我正在vue.js上工作,后端是laravel。我不熟悉这些技术 我试图在基于vue材质语法的表中显示父行和子行中的数据 我的Laravel控制器函数包含以下代码 $tasks = Task::select('tasks_status', DB::raw("group_concat(CONCAT('{\"id\":\"',id,'\",\"name\":\"',name,'\"}') ) as subro

我正在vue.js上工作,后端是laravel。我不熟悉这些技术

我试图在基于vue材质语法的表中显示父行和子行中的数据

我的Laravel控制器函数包含以下代码

 $tasks = Task::select('tasks_status', DB::raw("group_concat(CONCAT('{\"id\":\"',id,'\",\"name\":\"',name,'\"}') ) as subrow"))
                    ->where('tasks_status', '<>', "Sent Tasks")
                    ->whereNull('user_id')
                    ->orderBy('id', 'desc')
                    ->groupBy('tasks_status')
                    ->get();
在线JSON解析器验证它

在Vue前端中,我尝试使用2 for循环显示此JSON数据,如下所示

<md-table v-model="searched" md-sort="name" md-sort-order="asc" md-fixed-header class="table-sort">
   <md-table-toolbar>
      <div class="md-toolbar-section-start">
         <h1 class="md-title">Tasks</h1>
      </div>
      
      <md-field md-clearable class="md-toolbar-section-end">
         <label for="Tasks">Tasks</label>
         <md-select v-model="fieldsSearchTerm.searchTermForDataTable" name="search" id="search" @input="searchOnTable" >
            <md-option value="">All Tasks</md-option>
            <md-option value="My Tasks">My Tasks</md-option>
            <md-option value="Organization Tasks"
               >Organization Tasks</md-option
               >
            <md-option value="Received Tasks"
               >Received Tasks</md-option
               >
            <md-option value="Completed Task"
               >Completed Task</md-option
               >
            <md-option value="Incomplete Tasks"
               >Incomplete Tasks</md-option
               >
            <md-option value="Sent Tasks">Sent Tasks</md-option>
         </md-select>
      </md-field>
      <md-field md-clearable class="md-toolbar-section-end">
         <b-button class="btn btn-danger modal-btn" block @click="changeStatusToDone">Done</b-button>
      </md-field>
   </md-table-toolbar>
   <md-table-empty-state
      md-label="No data found">
   </md-table-empty-state>
   <md-table-row slot="md-table-row" v-for="rowHeading in searched" >
      <md-table-cell   md-label="Task Name" md-sort-by="name">{{ rowHeading.tasks_status }}</md-table-cell>
      <md-table-cell  md-label="Task Status" md-sort-by="tasks_status"></md-table-cell>
      <md-table-cell  md-label="Due Date" md-sort-by="due_date"></md-table-cell>
      <md-table-cell  md-label="Priority" md-sort-by="priority"></md-table-cell>
      <md-table-cell md-label="Actions" md-sort-by="">
      </md-table-cell>
   </md-table-row>
   <md-table-row slot="md-table-row" v-for="subRowElements in rowHeading.subrow">
      <md-table-cell md-label="" md-sort-by="" >
      </md-table-cell>
      <md-table-cell colspan=4  md-label="Task Name" md-sort-by="name">hi {{ subRowElements }}</md-table-cell>
      </md-table-cell>
   </md-table-row>
</md-table>

任何人都可以建议一种从控制器获取有效JSON的方法,并在vue.js页面中使用正确的循环显示它。提前感谢。

我认为您应该在Laravel控制器中使用类似的东西,这样使用循环输出json就更容易了

 $tasks = Task::select('tasks_status', DB::raw("group_concat(CONCAT('{\"id\":\"',id,'\",\"name\":\"',name,'\"}') ) as subrow"))
                    ->where('tasks_status', '<>', "Sent Tasks")
                    ->whereNull('user_id')
                    ->orderBy('id', 'desc')
                    ->groupBy('tasks_status')
                    ->get()->map(function ($e) {
                          $e->subrow = json_decode($e->subrow);
                          return $e;
                     });
$tasks=Task::select('tasks\'status',DB::raw(“组”\'concat(concat('{\'id\':\”,id,'\',\'name\':\”,name,'\'}'))作为子代码)
->其中('tasks\u status',''“已发送任务”)
->whereNull('user\u id')
->orderBy('id','desc')
->groupBy(“任务\状态”)
->get()->map(函数($e){
$e->subrow=json_解码($e->subrow);
返回$e;
});

如果将
subrow
值从字符串转换为数组,将更加容易。然后您只需定义一个
v-for=“subrow中的项”…
 import Cookies from 'js-cookie'
   import axios from "axios"
   
   import Vue from 'vue'
   import VueResource from 'vue-resource'
   
   
   import Form from 'vform'
   
   
   const toLower = text => {
   return text.toString().toLowerCase()
   }
   
   const searchByName = (items, term) => {
   if (term) {
     return items.filter(item => toLower(item.tasks_status).includes(toLower(term)))
   }
   
   return items
   }
   
   export default {
   name: 'TableSearch',
   
   
    components: {
   },
   
   
   data() {
   
   
            form: new Form({
     tasks_statusUpdate: '',
     nameUpdate: '',
     priorityUpdate: '',
     task_descriptionUpdate: '',
     dueDateUpdate: '',
     taskAssignedToUserUpdate: '',
     _token: Cookies.get('token')
   
   })
   
   
   
   
   return {
   goods: [],
   fieldsUpdate: {
         tasks_statusUpdate: "",
         nameUpdate: "",
         priorityUpdate: "",
         task_descriptionUpdate: '',
         dueDateUpdate: "",
         taskAssignedToUserUpdate: "",
         _token: Cookies.get('token'),
       },
   fieldsView: {
         tasks_statusView: "",
         nameView: "",
         priorityView: "",
         task_descriptionView: '',
         dueDateView: "",
         taskAssignedToUserView: "",
         userNameView: "",
       },
   fieldsTaskDone: {
     tasks_status: 1,
       },
                     
   fieldsSearchTerm: {
     searchTermForDataTable: '',
       },
   
                   fieldsCheckBox: {
     cboTaskName: true,
     cboTaskStatus: true,
     cboDueDate: true,
     cboPriority: true,
       },
                     
   
    isOpen: true,
    rows: null,
    allUsersUpdate: [],
              searched: [],
              rowHeading:[],
              subRowElements:[],
              
              
   
   users: [
       {
         id: 1,
         name: "Shawna Dubbin",
         email: "sdubbin0@geocities.com",
         date: "20/02/2021",
         priority: "High"
       },
       {
         id: 2,
         name: "Shawna Dubbin",
         email: "sdubbin0@geocities.com",
         date: "20/02/2021",
         priority: "High"
       },
       {
         id: 3,
         name: "Shawna Dubbin",
         email: "sdubbin0@geocities.com",
         date: "20/02/2021",
         priority: "High"
       },
       {
         id: 4,
         name: "Shawna Dubbin",
         email: "sdubbin0@geocities.com",
         date: "20/02/2021",
         priority: "High"
       },
       {
         id: 5,
         name: "Shawna Dubbin",
         email: "sdubbin0@geocities.com",
         date: "20/02/2021",
         priority: "High"
       },
       {
         id: 6,
         name: "Shawna Dubbin",
         email: "sdubbin0@geocities.com",
         date: "20/02/2021",
         priority: "High"
       },
       {
         id: 7,
         name: "Shawna Dubbin",
         email: "sdubbin0@geocities.com",
         date: "20/02/2021",
         priority: "High"
       },
       {
         id: 8,
         name: "Shawna Dubbin",
         email: "sdubbin0@geocities.com",
         date: "20/02/2021",
         priority: "High"
       },
       {
         id: 9,
         name: "Shawna Dubbin",
         email: "sdubbin0@geocities.com",
         date: "20/02/2021",
         priority: "High"
       },
       {
         id: 10,
         name: "Shawna vishal",
         email: "sdubbin0@geocities.com",
         date: "20/02/2021",
         priority: "High"
       },
     
     ],
     rows: [],
     editing_record_id: 0,
     view_record_id: 0,
     checkedTaskIDs: [],
     dynamicColumn: [],
     
   }
   },
   
   
   
   
 
           
   methods: {
     newUser () {
       window.alert('Noop')
     },
     searchOnTable () {
         this.makeGetRequest();
       this.searched = searchByName(this.rows, this.search)
     },
          
               
                    
                          fnDynamicColumns: function(e){
     
         
             if (e.target.checked) {
       console.log(e.target.value)
     } 
     

    },
   
     
   check_task_id: function(e) {
     if (e.target.checked) {
       console.log(e.target.value)
     }
   },      
     
     changeStatusToDone () {
   
           
       
         axios
           .post("api/v1/tasks/"+this.checkedTaskIDs+"/complete", 
   this.fieldsTaskDone
                 )
                     .then(response => {
             alert("Task Done!");
           })
           .catch(error => {
             console.log(error);
           });
   
           this.makeGetRequest();
           
                   
       
       
   
           
           },
     
     async makeGetRequest() {
   
   
       console.log("makeGetRequest begin ");
   
           
           var fnRows  = [];
           
        await   axios.get('api/v1/tasks', {
   params: {
     searchTermForDataTable: this.fieldsSearchTerm.searchTermForDataTable
   }
   })
       .then((response) => {
               this.rows = response.data;
               fnRows = response.data;
       
      console.log("inside axios > makeGetRequest" + JSON.stringify(this.rows));
   
           
           });
           
           
                 this.searched = this.rows
   
       console.log("makeGetRequest later " + this.searched);
           
           },
   
   
         async getAllUsers() {
       console.log("table > getAllUsers begin ");
        await   axios.get('api/v1/getallusers')
       .then((response) => {
               this.allUsersUpdate = response.data;
           });
   console.log("table > outside axios user11" + this.allUsersUpdate);
           
           },
           
           
    submitUpdateForm() {
             console.log(this.fieldsUpdate);
   
   console.log(Cookies.get('token'));
         axios
           .put("api/v1/tasks/"+this.editing_record_id, 
   this.fieldsUpdate
                 )
                     .then(response => {
             alert("Task Updated!");
             //this.fields = {};
           })
           .catch(error => {
             console.log(error);
           });
   
           this.makeGetRequest();
           
           
             console.log("ppppnnnnnn");
            
             
   },
           
           
           
           
           
     async getTask() {
        await   axios.get('api/v1/tasks/'+this.editing_record_id)
       .then((response) => {
           
           
               this.fieldsUpdate.tasks_statusUpdate = response.data[0].tasks_status;
               this.fieldsUpdate.nameUpdate = response.data[0].name;
               this.fieldsUpdate.taskAssignedToUserUpdate = response.data[0].user_id;
               this.fieldsUpdate.priorityUpdate = response.data[0].priority;
               this.fieldsUpdate.task_descriptionUpdate = response.data[0].task_description;
               
                       
                       if(response.data[0].due_date !== null)
                       {
                       this.fieldsUpdate.dueDateUpdate = response.data[0].due_date;
                   }
                   
                   
                   
                   console.log("getTask With Join" + JSON.stringify(response.data[0]));
   
       
       
           });
   console.log("getTask With Join" + JSON.stringify(this.fieldsUpdate));
           
           },
          
           
   showUpdateModal(id) {
           this.editing_record_id = id;
           this.getTask();
           
           
           this.$bvModal.show('taskUpdateModal')
       },
   
           
   softDeleteTask(id) {
   
   if(confirm("Are you sure, you want to delete, this task?")){
   
               
         axios
           .delete("api/v1/tasks/"+id)
                     .then(response => {
             alert("Task Deleted!");
             //this.fields = {};
           })
           .catch(error => {
             console.log(error);
           });
   
           this.makeGetRequest();
           
   }    
   
       },
   
       
     async getTaskForView() {
   
        await   axios.get('api/v1/tasks/'+this.view_record_id)
       .then((response) => {
           
   
           
               this.fieldsView.tasks_statusView = response.data[0].tasks_status;
               this.fieldsView.nameView = response.data[0].name;
               this.fieldsView.taskAssignedToUserView = response.data[0].user_id;
               this.fieldsView.priorityView = response.data[0].priority;
               this.fieldsView.task_descriptionView = response.data[0].task_description;
                       this.fieldsView.dueDateView = response.data[0].due_date;
                       this.fieldsView.userNameView = response.data[0].userName;
   
       
           });
   console.log("getTask" + JSON.stringify(this.fieldsView));
           
           },        
       
               
   showViewModal(id) {
           this.view_record_id = id;
           this.getTaskForView();
           
           
           this.$bvModal.show('taskViewModal')
       },        
       
       
           
           },
   
   
   created () {
   
   console.log("inside created()1");
              
   this.makeGetRequest();
   this.getAllUsers();
          
              
   
   console.log("outside axios" + this.rows);
   
   
   

    enter code here

   
     console.log("inside created() 2");
   },
   mounted() {
     console.log("inside mounted()")
   },
   
   }
 $tasks = Task::select('tasks_status', DB::raw("group_concat(CONCAT('{\"id\":\"',id,'\",\"name\":\"',name,'\"}') ) as subrow"))
                    ->where('tasks_status', '<>', "Sent Tasks")
                    ->whereNull('user_id')
                    ->orderBy('id', 'desc')
                    ->groupBy('tasks_status')
                    ->get()->map(function ($e) {
                          $e->subrow = json_decode($e->subrow);
                          return $e;
                     });