vuejs v model instant update by selecting html - search

I am very new to vue and have question.
I have following calendar in html.
<div class="year">2018</div>
<div class="month disabled">JAN</div>
<div class="month disabled">FEB</div>
<div class="month disabled">MAR</div>
<div class="month disabled">APR</div>
<div class="month disabled">MAY</div>
<div class="month disabled">JUN</div>
<div class="month disabled">JUL</div>
<div class="month disabled">AUG</div>
<div class="month disabled">SEP</div>
<div class="month disabled">OCT</div>
<div class="month disabled">NOV</div>
<div class="month ">DEC</div>
<br>
<div class="year">2019</div>
<div class="month disabled">JAN</div>
<div class="month disabled">FEB</div>
<div class="month disabled">MAR</div>
<div class="month disabled">APR</div>
<div class="month disabled">MAY</div>
<div class="month disabled">JUN</div>
<div class="month disabled">JUL</div>
<div class="month disabled">AUG</div>
<div class="month disabled">SEP</div>
<div class="month disabled">OCT</div>
<div class="month disabled">NOV</div>
<div class="month ">DEC</div>
<br>
<div>
{{product_list}}
</div>
</div>
Everytime the user clicks the month, I want to update product_list shown only items in the same month. The month is multi selective. only div without disabled is selectable
For example, when user selects JAN, MAR in 2018, I want to show products which have date in JAN and MAR in 2018.
here is sameple product list
$product = [
"id" => 1,
"productDates" => [
["id" => 109,
"product_id" => 10,
"departure_date" => "2018-12-11"
],
["id" => 110,
"product_id" => 10,
"departure_date" => "2018-3-11"
],
["id" => 109,
"product_id" => 10,
"departure_date" => "2019-12-11"
],
["id" => 110,
"product_id" => 10,
"departure_date" => "2018-4-11"
],
["id" => 109,
"product_id" => 10,
"departure_date" => "2018-4-12"
],
["id" => 110,
"product_id" => 10,
"departure_date" => "2018-5-21"
],
]
];
var opVm = new Vue({
el: "#departure-date-list",
data: {
seasons:{!! json_encode($seasons) !!},
product:{!! json_encode($product) !!},
productDates:{!! json_encode($product->productDates) !!},
datePax:{!! json_encode($datePax) !!},
},
methods: {
select:function(year,month){
console.log(year);
}
}
});

Related

How to display JSON object with Handlebars template

I am trying to create a react-like component with Handlebars. In this project, I have a set of project cards that are inside a carousel. The cards consist of a photo, project name, project description, and project link. The information is being pulled from an API that I create with the JSON data looking something like this
[
{
_id: '627b281c0ee7f8ee7eb08703',
name: 'Pamela',
about: "Pamela's portfolio page",
github: "pam's portfolio",
website: 'https://github.com/AlexAntoine/Devcamper-api/blob/main/models/Bootcamp.js',
tools: [ 'node js', 'Express', 'heroku', 'mongoDB', 'mongoose' ],
content: [],
__v: 0
},
{
_id: '627b284f0ee7f8ee7eb08706',
name: 'Mike',
about: "Mike's portfolio page",
github: "mike's portfolio",
website: 'https://github.com/AlexAntoine/Devcamper-api/blob/main/models/Bootcamp.js',
tools: [ 'node js', 'Express', 'heroku', 'mongoDB', 'mongoose', 'React' ],
content: [],
__v: 0
},
{
_id: '627b28b00ee7f8ee7eb08709',
name: 'Alex',
about: "Alex's portfolio page",
github: "alex's portfolio",
website: 'https://github.com/AlexAntoine/Devcamper-api/blob/main/models/Bootcamp.js',
tools: [
'node js',
'Express',
'heroku',
'mongoDB',
'mongoose',
'Angular'
],
content: [],
__v: 0
}
]
My goal is to have a new card created with the information from each object. For example, the first card would be populated with "Pamela", "Pamela's portfolio page", and "https://github.com/AlexAntoine/Devcamper-api/blob/main/models/Bootcamp.js " The starting HBS code I have for this is
{{#each this}}
{{>header}}
<section class="s1">
<div class="main-container">
<div class="greeting-wrapper">
<h1>Hello I'm Don-Alex 2</h1>
</div>
<div class="intro-wrapper" >
<div class="nav-wrapper">
<div class="dots-wrapper">
<div id="dot-1" class="browser-dots"></div>
<div id="dot-2" class="browser-dots"></div>
<div id="dot-3" class="browser-dots"></div>
</div>
<ul id="navigation">
<li>Contact</li>
</ul>
</div>
<div class="left-column">
<img id="profile-pic" src="https://images.unsplash.com/photo-1524502397800-2eeaad7c3fe5?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" alt="Profile Picture">
<h5 >Personalize Theme</h5>
<div id="theme-options-wrapper">
<div data-mode="light" class="theme-dot" id="light-mode"></div>
<div data-mode="blue" class="theme-dot" id="blue-mode"></div>
<div data-mode="green" class="theme-dot" id="green-mode"></div>
<div data-mode="purple" class="theme-dot" id="purple-mode"></div>
</div>
<p id="setting-note">*Theme options will be saved for<br>your next visit</p>
</div>
<div class="right-column">
<div id="preview-shadow">
<div id="preview">
<div id="corner-tl" class="corner"></div>
<div id="corner-tr" class="corner"></div>
<h3>What I Do </h3>
<p>Aspring software developer that enjoys building new things</p>
<div id="corner-br" class="corner"></div>
<div id="corner-bl" class="corner"></div>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="s2">
<div class="main-container">
<div class="about-wrapper">
<div class="about-me">
<h4>More about me</h4>
<p>Love watching anime and taking naps. </p>
<hr>
<h4>Top Expertise</h4>
<p>What i'm good at Download Resume </p>
<div id="skills">
<ul>
<li>HTML</li>
<li>CSS</li>
<li>Javascript</li>
<li>React</li>
<li>Bootstrap</li>
</ul>
<ul>
<li>Node.js</li>
<li>Mongoose</li>
<li>Express</li>
<li>MongoDB</li>
<li>Heroku</li>
</ul>
</div>
</div>
<div class="social-links">
<img id="social-img" src="https://images.unsplash.com/photo-1618401471353-b98afee0b2eb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1488&q=80" alt="Github">
<h3>Find my latest projects on Github</h3>
Github
<br>
</div>
</div>
</div>
</section>
<section class="s1">
<div class="main-container s1-container">
<h3>Some of My Past Projects</h3>
<div class="post-wrapper">
<div id="carouselExampleInterval" class="carousel slide" data-ride="carousel" data-pause="hover">
<div class="carousel-inner">
<!--Add loop here. Figure out how that is going to work out. -->
<div class="carousel-item active container-fluid temp-container" data-interval="3000">
<div class="post">
<div class="card-container">
<img class="thumbnail" src="https://images.unsplash.com/photo-1514474959185-1472d4c4e0d4?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1674&q=80" alt="">
<div class="post-preview">
<h6 class="post-title">{{this.name}}</h6>
<p class="post-intro">{{this.about}}</p>
1
</div>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleInterval" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleInterval" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
</section>
<section class="s2" id="one">
<div class="main-container">
<h3>Get In Touch</h3>
<form action="/" id="contact-form">
<label for="">Name</label>
<input type="text" class="input-field" name="name">
<label>Subject</label>
<input type="text" name="subject" class="input-field">
<label>Email</label>
<input type="text" name="email" class="input-field">
<label>Message</label>
<textarea class="input-field" name="message"></textarea>
{{!-- <input type="submit" name="submit-btn" value="send" id="submit-btn"> --}}
<input type="submit" value="send" id="submit-btn">
</form>
</div>
</section>
{{>footer}}
{{/each}}
The server-side code that sends the data is written like this
app.get('/home2', async(req, res)=>{
const {data:{result}}= await axios.get(`https://antoine-portfolio-api.herokuapp.com/api/v1/projects`);
const projects= result.map((projects)=>{
// console.log('line 62: ', project);
return projects;
});
res.render('home2',{
// title:'Alex home',
name: projects,
about: projects
})
})
I cannot get the program to display the project name and the description for all three of the projects listed. Any help would be appreciated. Thank you.

Infinit loop with axios call

I have a problem to loading data with API call with axios, I have an infinit loop when the method loadTasks() is called.
I want to load todo list, and load associated tasks inside. Maybe I'm using the wrong way.
Here my template with Todo liste v-for loop and inside an another v-loop lo display Task list associated, loaded with loadTasks(list.id).
<template >
<div class="todo-list-container">
<div class="list flex flex-col max-w-sm mx-auto">
<hr class="text-gray1 mb-4">
<div v-for="list in allTodoList" :value="list.id" :key="list.id" class="mb-4 px-4 py-2 bg-gray-dark rounded-xl ">
<div class="flex items-center gap-4 mb-4">
<div class="date text-sm text text-left text-gray1">{{ list.order }}</div>
<div class="title font-bold">{{ list.title }}</div>
<div class="ml-auto font-bold text-right">
<button v-if="list.id" #click="this.$store.dispatch('removeTodoList', list.id)">Supprimer</button>
</div>
</div>
<div class="task-container">
{{loadTasks(list.id)}}
<div v-if="loading">loading...</div>
<div v-if="tasks" class="list weekList flex flex-col p-6 max-w-sm mx-auto bg-gray rounded-xl shadow-lg">
<div class="flex flex-row gap-4">
Liste des taches <button #click="displayForm(list.id)" href="#" class="px-2 rounded bg-blue text-white text-sm uppercase right">+</button>
<hr class="text-gray1 mb-4">
</div>
<div v-for="task in tasks" :value="task.id" :key="task.id" class=" mb-4 flex items-center gap-4 flex-row">
<div class="date text-sm text text-left text-gray1">{{ task.position }}</div>
<div class="">
<div class="title font-bold">{{ task.title }}</div>
<div class="date text-sm text text-left text-gray1">Terminé <input type="checkbox" name="finish" id="" :checked="task.finish" ></div>
</div>
<div class="ml-auto font-bold text-right">
<button v-if="task.id" #click="this.$store.dispatch('removeTask', task.id)">Supprimer</button>
</div>
</div>
</div>
</div>
</div>
{{this.$store.state.error}}
<div :class="[ showForm === true ? '' : 'hidden' ] + ' addNewForm'">
<add-task-form :listId="getListId" :showForm="showForm" ></add-task-form>
</div>
</div>
</div>
</template>
Script:
<script>
import addTaskForm from './addTaskForm.vue';
import axios from 'axios';
axios.defaults.baseURL = 'http://localhost:3000';
export default {
name: 'todoList',
props: ['allTodoList'],
components: {
addTaskForm,
},
data() {
return {
loading: false,
visibleForm: false,
listId: 0,
tasks: [],
};
},
methods: {
displayForm(listId) {
this.listId = listId;
this.visibleForm = !this.visibleForm;
},
async loadTasks(listId) {
try {
if(!listId) { return; }
const tasksList = await axios.get(`/list/${listId}/tasks`);
if (!tasksList.data.tasks || !tasksList.data.tasks.length) {
return;
}
else {
this.tasks = tasksList.data.tasks
}
} catch (error) {
this.$store.dispatch('setError', error);
}
},
cancelForm() {
this.visibleForm = false;
},
},
computed: {
showForm() {
return this.visibleForm;
},
getListId() {
return this.listId;
},
},
}
</script>

Vue not opens .json file with axios hook

Making my first steps in vue. I am crashing in importing a .json file. This job concernes a small shop. Goal of this paragraph is to enter 4 products in the shop. The productfiles are imported with an Axios hook. But the Vue Dev Tool errors an undefined (see picture). When loading the website the div with v-else is automatically loaded.
The products.json files is nested in the same folder as index.html. http://localhost:8000/products.json shows me the .json file.
Here you 'll find all the code for this small shop. Even with a copy/paste of this code mine is not working. I also made it smaller with the relevant code:
<!DOCTYPE html>
<html>
<head>
<title>Vue.js Pet Depot</title>
<script src="https://unpkg.com/vue"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="assets/css/app.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.16.2/axios.js"></script>
<meta charset="UTF-8">
</head>
<body>
<div class="container">
<div id="app">
<header>
<div class="navbar navbar-default">
<div class="navbar-header">
<h1>{{ sitename }}</h1>
</div>
<div class="nav navbar-nav navbar-right cart">
<button type="button" class="btn btn-default btn-lg" v-on:click="showCheckout">
<span class="glyphicon glyphicon-shopping-cart">{{ cartItemCount}}</span> Checkout
</button>
</div>
</div>
</header>
<main>
<div v-if="showProduct"> <!--not working-->
<div v-for="product in sortedProducts">
<div class="row">
<div class="col-md-5 col-md-offset-0">
<figure>
<img class="product" v-bind:src="product.image">
</figure>
</div>
<div class="col-md-6 col-md-offset-0 description">
<h1 v-text="product.title"></h1>
<p v-html="product.description"></p>
<p class="price">
{{product.price | formatPrice}}
</p>
<button class=" btn btn-primary btn-lg" v-on:click="addToCart(product)" v-if="canAddToCart(product)">Add to cart</button>
<button disabled="true" class=" btn btn-primary btn-lg" v-else>Add to cart</button>
<span class="inventory-message" v-if="product.availableInventory - cartCount(product.id) === 0">
All Out!
</span>
<span class="inventory-message" v-else-if="product.availableInventory - cartCount(product.id) < 5">
Only {{product.availableInventory - cartCount(product.id)}} left!
</span>
<span class="inventory-message" v-else>
Buy Now!
</span>
<div class="rating">
<span v-bind:class="{'rating-active' :checkRating(n, product)}" v-for="n in 5">
☆
</span>
</div>
</div>
<!-- end of col-md-6-->
</div>
<!-- end of row-->
<hr />
</div>
<!-- end of v-for-->
</div>
<!-- end of showProduct-->
<div v-else>
<!--skipped this part-->
</div>
</main>
</div>
<!-- end of app-->
</div>
<script type="text/javascript">
var APP_LOG_LIFECYCLE_EVENTS = true;
var webstore = new Vue({
el: '#app',
data: {
sitename: "Vue.js Pet Depot",
showProduct: true,
a: false,
states: []
},
order: []
},
products: [],
cart: []
},
methods: {
checkRating(n, myProduct) {
return myProduct.rating - n >= 0;
},
addToCart(aProduct) {
this.cart.push(aProduct.id);
},
showCheckout() {
this.showProduct = this.showProduct ? false : true;
},
submitForm() {
alert('Submitted');
},
canAddToCart(aProduct) {
//return this.product.availableInventory > this.cartItemCount;
return aProduct.availableInventory > this.cartCount(aProduct.id);
},
cartCount(id) {
let count = 0;
for (var i = 0; i < this.cart.length; i++) {
if (this.cart[i] === id) {
count++;
}
}
return count;
}
},
computed: {
cartItemCount() {
return this.cart.length || '';
},
sortedProducts() {
if (this.products.length > 0) {
let productsArray = this.products.slice(0);
console.log(productsArray);
console.log(this.products);
function compare(a, b) {
if (a.title.toLowerCase() < b.title.toLowerCase())
return -1;
if (a.title.toLowerCase() > b.title.toLowerCase())
return 1;
return 0;
}
return productsArray.sort(compare);
}
}
},
filters: {
formatPrice(price) { //#B
..
}
},
beforeCreate: function () { //#B
if (APP_LOG_LIFECYCLE_EVENTS) { //#B
..
},
created: function () {
axios.get('./products.json')
.then((response) => {
this.products = response.data.products;
console.log(this.products);
});
},
beforeMount: function () {
..
},
mounted: function () {
..
},
beforeUpdate: function () {
..
},
updated: function () {
..
},
beforeDestroyed: function () {
..
},
destroyed: function () {
..
}
});
</script>
</body>
</html>
I tried out the same code here and it's working fine, i had did axios call to this json file :
https://raw.githubusercontent.com/ErikCH/VuejsInActionCode/master/chapter-05/products.json
<!DOCTYPE html>
<html>
<head>
<title>Vue.js Pet Depot</title>
<script src="https://unpkg.com/vue"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="assets/css/app.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.16.2/axios.js"></script>
<meta charset="UTF-8">
</head>
<body>
<div class="container">
<div id="app">
<header>
<div class="navbar navbar-default">
<div class="navbar-header">
<h1>{{ sitename }}</h1>
</div>
<div class="nav navbar-nav navbar-right cart">
<button type="button" class="btn btn-default btn-lg" v-on:click="showCheckout">
<span class="glyphicon glyphicon-shopping-cart">{{ cartItemCount}}</span> Checkout
</button>
</div>
</div>
</header>
<main>
<div v-if="showProduct">
<div v-for="product in sortedProducts">
<div class="row">
<div class="col-md-5 col-md-offset-0">
<figure>
<img class="product" v-bind:src="product.image">
</figure>
</div>
<div class="col-md-6 col-md-offset-0 description">
<h1 v-text="product.title"></h1>
<p v-html="product.description"></p>
<p class="price">
{{product.price | formatPrice}}
</p>
<button class=" btn btn-primary btn-lg" v-on:click="addToCart(product)" v-if="canAddToCart(product)">Add to cart</button>
<button disabled="true" class=" btn btn-primary btn-lg" v-else>Add to cart</button>
<span class="inventory-message" v-if="product.availableInventory - cartCount(product.id) === 0">All Out!
</span>
<span class="inventory-message" v-else-if="product.availableInventory - cartCount(product.id) < 5">
Only {{product.availableInventory - cartCount(product.id)}} left!
</span>
<span class="inventory-message" v-else>Buy Now!
</span>
<div class="rating">
<span v-bind:class="{'rating-active' :checkRating(n, product)}" v-for="n in 5">☆
</span>
</div>
</div>
<!-- end of col-md-6-->
</div>
<!-- end of row-->
<hr />
</div>
<!-- end of v-for-->
</div>
<!-- end of showProduct-->
<div v-else>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-info">
<div class="panel-heading">Pet Depot Checkout</div>
<div class="panel-body">
<div class="form-group">
<div class="col-md-12">
<h4>
<strong>Enter Your Information</strong>
</h4>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<strong>First Name:</strong>
<input v-model.trim="order.firstName" class="form-control" />
</div>
<div class="col-md-6">
<strong>Last Name:</strong>
<input v-model.trim="order.lastName" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<strong>Address:</strong>
</div>
<div class="col-md-12">
<input v-model.trim="order.address" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<strong>City:</strong>
</div>
<div class="col-md-12">
<input v-model.trim="order.city" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-2">
<strong>State:</strong>
<select v-model="order.state" class="form-control">
<option disabled value="">State</option>
<option v-for="(state, key) in states" v-bind:value="state">
{{key}}
</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<strong>Zip / Postal Code:</strong>
<input v-model.number="order.zip" class="form-control" type="number" />
</div>
</div>
<div class="form-group">
<div class="col-md-6 boxes">
<input type="checkbox" id="gift" value="true" v-bind:true-value="order.sendGift" v-bind:false-value="order.dontSendGift" v-model="order.gift">
<label for="gift">Ship As Gift?</label>
</div>
</div>
<!-- end of form-group -->
<div class="form-group">
<div class="col-md-6 boxes">
<input type="radio" id="home" v-bind:value="order.home" v-model="order.method">
<label for="home">Home</label>
<input type="radio" id="business" v-bind:value="order.business" v-model="order.method">
<label for="business">Business</label>
</div>
</div>
<!-- end of form-group-->
<div class="form-group">
<div class="col-md-6">
<button type="submit" class="btn btn-primary submit" v-on:click="submitForm">Place Order</button>
</div>
<!-- end of col-md-6-->
</div>
<!-- end of form-group-->
<div class="col-md-12 verify">
<pre>
First Name: {{order.firstName}}
Last Name: {{order.lastName}}
Address: {{order.address}}
City: {{order.city}}
Zip: {{order.zip}}
State: {{order.state}}
Method: {{order.method}}
Gift: {{order.gift}}
</pre>
</div>
<!-- end of col-md-12 verify-->
</div>
<!--end of panel-body-->
</div>
<!--end of panel panel-info-->
</div>
<!--end of col-md-10 col-md-offset-1-->
</div>
<!--end of row-->
</div>
</main>
</div>
<!-- end of app-->
</div>
<script type="text/javascript">
var APP_LOG_LIFECYCLE_EVENTS = true;
var webstore = new Vue({
el: '#app',
data: {
sitename: "Vue.js Pet Depot",
showProduct: true,
a: false,
states: {
AL: 'Alabama',
AK: 'Alaska',
AR: 'Arizona',
CA: 'California',
NV: 'Nevada'
},
order: {
firstName: '',
lastName: '',
address: '',
city: '',
zip: '',
state: '',
method: 'Home Address',
business: 'Business Address',
home: 'Home Address',
gift: '',
sendGift: 'Send As A Gift',
dontSendGift: 'Do Not Send As A Gift'
},
products: {},
cart: []
},
methods: {
checkRating(n, myProduct) {
return myProduct.rating - n >= 0;
},
addToCart(aProduct) {
this.cart.push(aProduct.id);
},
showCheckout() {
this.showProduct = this.showProduct ? false : true;
},
submitForm() {
alert('Submitted');
},
canAddToCart(aProduct) {
//return this.product.availableInventory > this.cartItemCount;
return aProduct.availableInventory > this.cartCount(aProduct.id);
},
cartCount(id) {
let count = 0;
for (var i = 0; i < this.cart.length; i++) {
if (this.cart[i] === id) {
count++;
}
}
return count;
}
},
computed: {
cartItemCount() {
return this.cart.length || '';
},
sortedProducts() {
if (this.products.length > 0) {
let productsArray = this.products.slice(0);
function compare(a, b) {
if (a.title.toLowerCase() < b.title.toLowerCase())
return -1;
if (a.title.toLowerCase() > b.title.toLowerCase())
return 1;
return 0;
}
return productsArray.sort(compare);
}
}
},
filters: {
formatPrice(price) { //#B
if (!parseInt(price)) {
return "";
} //#C
if (price > 99999) { //#D
var priceString = (price / 100).toFixed(2); //#E
var priceArray = priceString.split("").reverse(); //#F
var index = 3; //#F
while (priceArray.length > index + 3) { //#F
priceArray.splice(index + 3, 0, ","); //#F
index += 4; //#F
} //#F
return "$" + priceArray.reverse().join(""); //#G
} else {
return "$" + (price / 100).toFixed(2); //#H
}
}
},
created: function() { //#C
axios.get('https://raw.githubusercontent.com/ErikCH/VuejsInActionCode/master/chapter-05/products.json')
.then((response) => {
this.products = response.data.products;
// console.log(this.products);
});
}
});
</script>
</body>
</html>

Saving contenteditable Content Changes

Good Day! I am a newbie in asp.net MVC 5 and is working on a form where one cell is editable then it will be saved in the database, along with the values of the other cells. I've managed to make the cell editable using contenteditable="true" . This is my View:
<div class="container">
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<div class="col-lg-12">
<div class="col-lg-6"></div>
<div class="col-lg-6">
<div class="form-horizontal">
<div class="form-group">
#Html.LabelFor(m => m.CUSTOMER_ID, "Customer Name", new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.DropDownList("CUSTOMER_ID", ViewBag.CustomerName as IEnumerable<SelectListItem>, "--Select Customer--", new { #class = "form-control" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.ORDER_DUE_DATE, "Due Date", htmlAttributes: new { #class = "col-lg-5" })
<div class="col-lg-7">
#Html.TextBoxFor(model => model.ORDER_DUE_DATE, "{0:yyyy-MM-dd}", new { #class = "form-control", #type = "date" })
#Html.ValidationMessageFor(model => model.ORDER_DUE_DATE, "", new { #class = "text-danger" })
</div>
</div>
</div><!--form-horizontal-->
</div>
</div><!--col lg 12-->
<table id="tbl_orderItems" class="table table-striped table-bordered table-hover dt-responsive nowrap" cellspacing="0">
<thead>
<tr>
<th>Item Code</th>
<th>Quantity</th>
<th>Unit</th>
<th>Item Description</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
#if (TempData["listOrder"] != null)
{
foreach (var items in TempData["listOrder"] as List<ebms.ViewModels.OrderItems>)
{ #Html.HiddenFor(modelItem => items.Id)
<tr>
<td>#items.PRODUCT_CODE</td>
<td contenteditable="true">#items.iQuantity</td>
<td>#items.MEASUREMENT_NAME</td>
<td>#items.ITEM_DESCRIPTION</td>
<td>#items.tmpStatus</td>
<td>
#Html.ActionLink("Remove", "Remove", new { id = items.Id },
new { onclick = "return confirm('Are sure want to remove?');" })
</td>
</tr>
}
}
</table>
<div id="menu1">
<ul>
<li>
<center><a>Select an Item</a></center>
<ul>
<li><a href='#Url.Action("Products", "Sales")'>Products </a></li>
</ul>
</li>
</ul>
</div>
<div class="form-group">
<div class="col-lg-3 pull-right">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</div>
}
</div>
I've put the contenteditable="true" in the quantity because it is the cell that should be editable. Most of the other values in there are from this form:
It will then be passed on to this form and the quantity should be editable.
Then the Customer will be chosen and the Order Due Date will be put in there as well. My problem is, the value that is typed to the editable cell is not saved in to the database. Can someone help me on how to use contenteditable="true" properly and then save it to the database? Thank you in advanced!

How to iterate objects in ectjs

Here is my code,
<div id="main" class="container">
<% for danceCategory, i in #danceStyle : %>
<% if #i? % 2 == 0 : %>
<div class="row">
<div class="col-md-5 zero_padding" align="center">
<img class="img-responsive" src='image/bollywood_master_class_image.png' />
</div>
<div class="col-md-7 zero_padding">
<div class="content_right">
<div>
<!-- <span class="heading_first"> #{danceCategory.category} </span> -->
<span class="heading_second"> <%- #danceCategory.category %> </span>
</div>
<ul class="dance_type">
</ul>
</div>
</div>
</div>
<% else : %>
<p>List is empty</p>
<% end %>
<% end %>
</div>
I am trying to iterate the dance categories.
Question :
How can can get the index of the iteration (i in this case)
<%- #danceCategory.category %> Not displaying any values (But I am
passing the values from node)
Something like this should do it, making sure that when you access the variables within the template you don't use the '#' accessor:
<div id="main" class="container">
<% for danceCategory, idx in #danceStyle : %>
<span>The index is <%= idx %> and category is <%= danceCategory.category %></span>
<% if idx % 2 == 0 : %>
<div class="row">
<div class="col-md-5 zero_padding" align="center">
<img class="img-responsive" src='image/bollywood_master_class_image.png' />
</div>
<div class="col-md-7 zero_padding">
<div class="content_right">
<div>
<span class="heading_second"> <%= danceCategory.category %> </span>
</div>
<ul class="dance_type"></ul>
</div>
</div>
</div>
<% else : %>
<p>List is empty</p>
<% end %>
<% end %>
</div>
Params:
{
title : 'Hello, world!',
id : 'main',
danceStyle: [
{ category : 'Contemporary', type : 'Traditional Jazz' },
{ category : 'Skanking', type : 'Native American' },
{ category : 'Shuffling', type : 'Traditional Jazz' },
{ category : 'Chicago stepping', type : 'Native American' },
{ category : 'Detroit Ballroom', type : 'Traditional Jazz' },
{ category : 'Disco dancing', type : 'Native American' },
{ category : 'Drunken Sailor', type : 'Traditional Jazz' },
{ category : 'Linya vrak dance', type : 'Native American' },
{ category : 'Swing', type : 'Traditional Jazz' },
{ category : 'Stomp dance', type : 'Native American' },
{ category : 'Texas Swingout', type : 'Traditional Jazz' },
{ category : 'Texas slidethrough', type : 'Native American' },
{ category : 'Texas Tommy', type : 'Traditional Jazz' },
{ category : 'Skanking', type : 'Native American' },
{ category : 'Ballroom', type : 'Traditional Jazz' }
],
upperHelper : function (string) {
return string.toUpperCase();
}
}
Output
<!DOCTYPE html>
<html>
<head>
<title>Hello, world!</title>
</head>
<body>
<div id="main" class="container"> <span>The index is 0 and category is Contemporary</span>
<div class="row">
<div class="col-md-5 zero_padding" align="center">
<img class="img-responsive" src='image/bollywood_master_class_image.png'
/>
</div>
<div class="col-md-7 zero_padding">
<div class="content_right">
<div> <span class="heading_second"> Contemporary </span>
</div>
<ul class="dance_type"></ul>
</div>
</div>
</div> <span>The index is 1 and category is Skanking</span>
<p>List is empty</p> <span>The index is 2 and category is Shuffling</span>
<div
class="row">
<div class="col-md-5 zero_padding" align="center">
<img class="img-responsive" src='image/bollywood_master_class_image.png'
/>
</div>
<div class="col-md-7 zero_padding">
<div class="content_right">
<div> <span class="heading_second"> Shuffling </span>
</div>
<ul class="dance_type"></ul>
</div>
</div>
</div> <span>The index is 3 and category is Chicago stepping</span>
<p>List is empty</p> <span>The index is 4 and category is Detroit Ballroom</span>
<div
class="row">
<div class="col-md-5 zero_padding" align="center">
<img class="img-responsive" src='image/bollywood_master_class_image.png'
/>
</div>
<div class="col-md-7 zero_padding">
<div class="content_right">
<div> <span class="heading_second"> Detroit Ballroom </span>
</div>
<ul class="dance_type"></ul>
</div>
</div>
</div> <span>The index is 5 and category is Disco dancing</span>
<p>List is empty</p> <span>The index is 6 and category is Drunken Sailor</span>
<div
class="row">
<div class="col-md-5 zero_padding" align="center">
<img class="img-responsive" src='image/bollywood_master_class_image.png'
/>
</div>
<div class="col-md-7 zero_padding">
<div class="content_right">
<div> <span class="heading_second"> Drunken Sailor </span>
</div>
<ul class="dance_type"></ul>
</div>
</div>
</div> <span>The index is 7 and category is Linya vrak dance</span>
<p>List is empty</p> <span>The index is 8 and category is Swing</span>
<div
class="row">
<div class="col-md-5 zero_padding" align="center">
<img class="img-responsive" src='image/bollywood_master_class_image.png'
/>
</div>
<div class="col-md-7 zero_padding">
<div class="content_right">
<div> <span class="heading_second"> Swing </span>
</div>
<ul class="dance_type"></ul>
</div>
</div>
</div> <span>The index is 9 and category is Stomp dance</span>
<p>List is empty</p> <span>The index is 10 and category is Texas Swingout</span>
<div
class="row">
<div class="col-md-5 zero_padding" align="center">
<img class="img-responsive" src='image/bollywood_master_class_image.png'
/>
</div>
<div class="col-md-7 zero_padding">
<div class="content_right">
<div> <span class="heading_second"> Texas Swingout </span>
</div>
<ul class="dance_type"></ul>
</div>
</div>
</div> <span>The index is 11 and category is Texas slidethrough</span>
<p>List is empty</p> <span>The index is 12 and category is Texas Tommy</span>
<div
class="row">
<div class="col-md-5 zero_padding" align="center">
<img class="img-responsive" src='image/bollywood_master_class_image.png'
/>
</div>
<div class="col-md-7 zero_padding">
<div class="content_right">
<div> <span class="heading_second"> Texas Tommy </span>
</div>
<ul class="dance_type"></ul>
</div>
</div>
</div> <span>The index is 13 and category is Skanking</span>
<p>List is empty</p> <span>The index is 14 and category is Ballroom</span>
<div
class="row">
<div class="col-md-5 zero_padding" align="center">
<img class="img-responsive" src='image/bollywood_master_class_image.png'
/>
</div>
<div class="col-md-7 zero_padding">
<div class="content_right">
<div> <span class="heading_second"> Ballroom </span>
</div>
<ul class="dance_type"></ul>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="left">Generated by ECT</div>
<div class="right">page: main</div>
</div>
</body>
</html>
For info, I have tested this on ectjs.com as I couldn't replicate it on jsfiddle and it works. Below is the screenshot of the above issue:

Resources