i have database table data in object form, like this
{"item_id": "1",
"item_color": "Black",
"item_size": "L",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "white",
"item_size": "M",
"item_Quantity": "5",},
{"item_id": "3",
"item_color": "green",
"item_size": "S",
"item_Quantity": "5",},
{"item_id": "4",
"item_color": "yellow",
"item_size": "S",
"item_Quantity": "5",}
i want display the data in table format.i am searching but i can,t find exact solution.
Something along the lines of:
<table>
<thead>
<tr>
<td>Color:</td>
<td>Size:</td>
<td>Quantity:</td>
</tr>
</thead>
<tbody>
#foreach($items as $item)
<tr>
<td>$item->item_color</td>
<td>$item->item_size</td>
<td>$item->item_quantity</td>
</tr>
#endforeach
</tbody>
</table>
Related
My two hash/maps are as below. I want to get the value corresponding to the key from the first map and second map and then add them to table
Map 1
[
{
"key": "1",
"value":"Potato"
},
{
"key": "2",
"value":"Chilly"
}
]
Map 2
[
{
"key": "1",
"value":"Apple"
},
{
"key": "2",
"value":"Plum"
}
]
I want the data in the fashion so that I can fetch data for the same key from both the map at the same time
<#list map1+map2?keys as key>
<tr>
<td>${key}</td>
<td >${map1[key]}</td>
<td >${map2[key]}</td>
</tr>
</#list>
I know I am doing something wrong, but not able to process the code. Can someone help?
You need to parenthesize the map concatenation in order to be able to use the built-in ?keys, so (map1 + map2)?keys. Also, you might want to check for empty values if the maps are not equal by suffixing your expression with !"default value", or simply ! if you want to have no default:
<#assign map1 = { "1": "Potato", "2": "Chilly" } >
<#assign map2 = { "1": "Apple", "2": "Plum", "3": "Extra" } >
<#list (map1 + map2)?keys as key>
<tr>
<td>${key}</td>
<td>${map1[key]!}</td>
<td>${map2[key]!}</td>
</tr>
</#list>
See also:
Freemarker - default value for variable that may be missing or blank?
if i use postman the data to get profile like this
{
"status": "success",
"status_code": 200,
"message": "OK",
"data": {
"id": 2,
"name": "ahsan",
"email": "ahsan#gmail.com",
"email_verified_at": "2019-12-24 08:40:35",
"password": "$2y$10$cr3bRfqZ3Fp3uxnqgInNCugwAdSNury3Nsn6GMl9T36kxT.36GmzS",
"remember_token": null,
"created_at": "2019-12-24 08:40:35",
"updated_at": "2019-12-24 08:40:35",
"member_pin": "xxxxxxx",
"google2fa_secret": null,
"google_2fa enum \"\"Y\"\",\"\"N\"\",": "N",
"reff_id": ""
}
}
how to get value? because the data not array format?
i have tried using v-for all data will be showing not rendering like list array format
You can use Object.keys to get all keys as array and use v-for to get values
var app = new Vue({
el: '#app',
data:{
test:{
"status": "success",
"status_code": 200,
"message": "OK",
"data": {
"id": 2,
"name": "ahsan",
"email": "ahsan#gmail.com",
"email_verified_at": "2019-12-24 08:40:35",
"password": "$2y$10$cr3bRfqZ3Fp3uxnqgInNCugwAdSNury3Nsn6GMl9T36kxT.36GmzS",
"remember_token": null,
"created_at": "2019-12-24 08:40:35",
"updated_at": "2019-12-24 08:40:35",
"member_pin": "xxxxxxx",
"google2fa_secret": null,
"google_2fa enum \"\"Y\"\",\"\"N\"\",": "N",
"reff_id": ""
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<div id="app">
<div v-for="key in Object.keys(test.data)"><strong>{{key}}</strong> : {{test.data[key]}}</div>
</div>
Another way to loop in vuejs v-for="key,index in test.data"
var app = new Vue({
el: '#app',
data:{
test:{
"status": "success",
"status_code": 200,
"message": "OK",
"data": {
"id": 2,
"name": "ahsan",
"email": "ahsan#gmail.com",
"email_verified_at": "2019-12-24 08:40:35",
"password": "$2y$10$cr3bRfqZ3Fp3uxnqgInNCugwAdSNury3Nsn6GMl9T36kxT.36GmzS",
"remember_token": null,
"created_at": "2019-12-24 08:40:35",
"updated_at": "2019-12-24 08:40:35",
"member_pin": "xxxxxxx",
"google2fa_secret": null,
"google_2fa enum \"\"Y\"\",\"\"N\"\",": "N",
"reff_id": ""
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<div id="app">
<div v-for="key,index in test.data"><strong>{{key}}</strong> : {{test.data[index]}}</div>
</div>
In your case you just need to store the response data in the data property like user and then simply write following code in your HTML template:
{{ user.email }}
You might not need v-for unless you have multiple users.
Consider the following component as an example (for multiple users).
<template>
<div>
<h1>Users</h1>
<table class="table">
<thead>
<tr>
<th scope="col">Email</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users" :key="user.email">
<td> {{ user.email }} </td>
<td>{{ user.first_name }}</td>
<td>{{ user.last_name }}</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
data() {
return {
users:null,
}
},
created() {
this.getUsers(); // Will make Laravel API call
},
methods: {
getUsers(){
this.axios.get("https://reqres.in/api/users").then((response) => {
this.users = response.data.data;
});
}
}
}
</script>
I have an Object structure that is store in Eloquent Form
{"item_id": "2",
"item_color": "Black",
"item_size": "L",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "Black",
"item_size": "M",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "Black",
"item_size": "S",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "White",
"item_size": "S",
"item_Quantity": "5",},
What I'm trying to achieve is to combine up all item_quantity which has the same item_id and item_color and Display in Table form like this.
ItemID ItemColor ItemSize Quantity Total
2 Black L-M-S 5-5-5 15
2 White S 5 5
In my research this is the nearest kind of solution but Im having trouble on displaying it in table form
http://stackoverflow.com/questions/23902541/add-array-values-of-same-array-keys-in-session
$items = DB::table('item')
->select(DB::raw("item_id,item_color,GROUP_CONCAT(item_size SEPARATOR '-') as ItemSize,GROUP_CONCAT(item_Quantity SEPARATOR '-') as Quantity,sum(item_Quantity) as TOTAL"))
->groupBy('item_id','item_color')
->get();
{
"id": "1",
"item_quantity": "3",
"item_id": "3",
"item_color": "White",
},
{
"id": "2",
"item_quantity": "3",
"item_id": "3",
"item_color": "Black",
},
{
"id": "3",
"item_quantity": "3",
"item_id": "4",
"item_color": "White",
},
Hi guys my output in Laravel using foreach is this,
ItemId:3 ItemQuantity:3 ItemColor:White
ItemId:3 ItemQuantity:3 ItemColor:Black
ItemId:4 ItemQuantity:3 ItemColor:White
But what I need is to combine those Item with the same ID like this,
ItemID:3 ItemQuantity:3 ItemColor:White/ ItemQuantity:3 ItemColor:Black
ItemId:4 ItemQuantity:3 ItemColor:White
BTW I use Table in my View, and Foreach to display may Data.
Thank you guys.. this is Laravel 4.2
#foreach($items as $item1)
<tr>{{$item1->id}}</td>
<td>{{$item1->item_quantity}}</td>
<td>{{$item1->item_color}}</td>
#foreach($items as $item2)
#if($item1->item_id == $item2->item_id)
<td>{{$item2->item_quantity}}</td>
<td>{{$item2->item_color}}</td>
#endif
#endforeach
</tr>
#endforeach
I am not sure what is your input objet but something like this:
function group_items($items){
$groupedOutput = array();
for each($items as $item){
$key = 'id_'.$item;
if(!array_key_exists($key, $groupedOutput)){
$groupedOutput[$key] = array();
}
$groupedOutput[$key][] = $item;
}
return $groupedOutput;
}
function print_items($groupedOutput){
for each($groupedOutput as $items){
for each($items as $item){
$itemId = $item['item_id'];
$itemQuantity = $item['item_quantity'];
$itemColor = $item['item_color'];
echo "ItemID:$itemId ItemQuantity:$itemQuantity ItemColor:$itemColor/ ";
}
}
}
//To group output
$groupedOutput = group_items($items);
//To print grouped output
print_items($groupedOutput);
// OR
var_dump(json_encode($groupedOutput));
I want to create a Date, Time and DateTime EditorTemplate using MVC3 and Razor.
For now, let's focus on the Time (I can fix the remaining templates later).
#model DateTime?
#using MyMvcApp.Properties
#Html.DropDownListFor(model => model.Value.Hour, new SelectList(new[] {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" },
Model.HasValue ? Model.Value.Hour.ToString("D2") : "00"), null, new { style = "width: auto; margin-left: 5px;" })
:
#{
List<string> availableMinutes = new List<string>();
for (int minute = 0; minute < 60; minute += 1)
{
availableMinutes.Add(minute.ToString("D2"));
}
#Html.DropDownListFor(model => model.Value.Minute, new SelectList(availableMinutes, Model.HasValue? Model.Value.Minute.ToString("D2") : "00"), null, new { style = "width: auto" });
}
<img alt="#Resources.SelectTime" src="../../../images/icon_clock_2.gif" style="margin-right: 5px" />
<input id="clearDate" type="button" value="#Resources.Clear" class="ui-state-default" />
The point is: how do I clear values of this editor template only? I can add a script that clears the values of the ID's, but then all the editortemplates of the same type would be cleared.
So my question: how can I clear all the values (hour and minute) of this template only when the clearDate button is clicked?
Thanks in advance!
You could wrap the entire template in a div container and simply walk the DOM with jQuery in context to the clearDate button. I'm doing this from memory, but it would be something like:
$(this).parent().children().contents().find("#hourElement").val("");