VueJS implement go to prev menu - vue.js

I am writing an app where a fixed length list gets generated based on the nested JSONArray. Whenever any elements gets clicked from the list and if it has a "sub data" array,the list gets populated with this "sub data". Basically, you can think of it as menus which has submenus and those submenus has subsubmenus and so on.
I have implemented two methods for going to sublevels [next()] which works fine but I don't know how to implement prev() method to go one level up in the menu. Currently, I can make it go one level up but if user is inside more than two level then I don't know how to keep the track of all above levels.
Here is the codepen -
codepen
let JSONModel = (_id, _lvl, _title, _data) => {
return {
id: _id,
lvl: _lvl,
title: _title,
data: _data
};
};
let Menu = [
{
id: "01",
lvl: "01",
title: "menu 1",
data: []
},
{
id: "02",
lvl: "01",
title: "menu 2",
data: []
},
{
id: "03",
lvl: "01",
title: "menu 3",
data: []
},
{
id: "04",
lvl: "01",
title: "menu 4",
data: [
{
id: "01",
lvl: "02",
title: "submenu 1",
data: []
},
{
id: "02",
lvl: "02",
title: "submenu 2",
data: [
{
id: "01",
lvl: "03",
title: "sub submenu 1",
data: []
},
{
id: "02",
lvl: "03",
title: "sub submenu 2",
data: []
},
{
id: "03",
lvl: "03",
title: "sub submenu 3",
data: []
},
{
id: "04",
lvl: "03",
title: "sub submenu 4",
data: []
}
]
},
{
id: "03",
lvl: "02",
title: "submenu 3",
data: []
},
{
id: "04",
lvl: "02",
title: "submenu 4",
data: []
}
]
}
];
let demo = new Vue({
el: "#app",
data: {
input: Menu,
prevMenu:[]
},
computed: {},
created: function () {
},
methods: {
next: function(val1,val2) {
if (val1.length != 0) {
this.input = val1;
this.prevMenu = val2;
console.log(this.prevMenu);
}
},
prev: function() {
console.log(this.prevMenu);
this.input = this.prevMenu;
}
}
});
$("#prevmenu").on("click", function() {
demo.prev();
});

Using your code, you can simply do this:
https://codepen.io/webkit_il/pen/bjebZR?editors=0011
next: function(val1,val2) {
if (val1.length != 0) {
this.input = val1;
this.prevMenu.push(val2);
}
},
prev: function() {
let _menu = this.prevMenu.slice(); // this is just to clone the array
this.input = _menu[_menu.length - 1];
this.prevMenu.pop();
}
changed your prevMenu into an array, then everytime you
go back just use the last one, and remove it from the array...
good luck!

Related

How to set default value for radio button in Sanity Studio?

I'm trying to set the default value given a list of radio items in Sanity Studio.
Code:
export default {
name: 'banner',
title: 'Banner',
type: 'document',
fields: [
{
name: "category",
title: "Category",
description: "Choose a category",
type: "string",
options: {
layout: "radio",
list: [
{ title: "Documentary", value: "documentary" },
{ title: "Fiction", value: "fiction" },
],
},
// set initial value here ?
},
]
}
There is a property called initialValue that can set the default value of a string easily, but I can't figure out how to do this with radio items.
How can I have the radio item Fiction already selected when the page is loaded?
name: 'banner',
title: 'Banner',
type: 'document',
fields: [
{
name: "category",
title: "Category",
description: "Choose a category",
type: "string",
options: {
layout: "radio",
list: [
{ title: "Documentary", value: "documentary" },
{ title: "Fiction", value: "fiction" },
],
},
initialValue: "documentary", // set initialValue's value to one of the `value`s in your list of radio items
},
]
}```

how to pass i18n data $t as prop to a component

in a normal way with out translation but i want to translate the two object array and bind into a component
<InfoNews
v-for="infonew in infonews"
:id="infonew.id"
:title="infonew.title"
:content="infonew.content"
/>
data() {
return {
infonews: [
{
id: "01",
title: "what we do",
content:"industke aecimen book. ",
},
{
id: "02",
title: "our mission",
content:"ggdddg",
},
],
};
Make infonews a computed property. The title and content of each should be the translation keys.
export default {
computed: {
infonews() {
return [
{
id: "01",
title: this.$t("what we do"),
content: this.$t("industke aecimen book"),
},
{
id: "02",
title: this.$t("our mission"),
content: this.$t("ggdddg"),
},
]
};
}
}

Surveyjs: choicesVisibleIf based on item property

Is it possible to enable/disable element in Dropdown based on item properties?
var json = {
questions: [
{
type: "dropdown",
name: "car",
title: "What car are you driving?",
isRequired: true,
colCount: 0,
choices: [
{ title: "One", value: "91", isDeleted: true },
{ title: "Two", value: "91", isDeleted: false },
{ title: "Three", value: "91", isDeleted: false }
],
/** What is the expression should I use here? */
choicesVisibleIf: "{item}.isDeleted == false"
}
]};
Here is a playground: https://plnkr.co/edit/LIp8pZbyXVB3UfBD
Thanks.
in my opinion tt would be easier to get choicesByUrl from a restFul Api & add an isDeleted Filter there /getChoices?isDeleted=true .....because anyway the title & value is going to by dynamic
var json = {
questions: [
{
type: "dropdown",
name: "car",
title: "What car are you driving?",
isRequired: true,
colCount: 0,
choicesByUrl: {
url: "https://getChoices/rest/v2?isDeleted=false",
valueName: "title"
}
}
]
};

Wanting to use DataTables to nest a table within a table...within a table...can it be done?

I just started using dataTables so I'm hoping this will be a learning opportunity.
I work for a school system and trying to develop a table that will show a student's grades from year to year. I want an administrator to be able to click on any year, and the table will expand to show a child table with the student's GPA for each term (6 terms per school year). Finally, I want the administrator to be able to click on any term and show a child table for actual classes the student took that term and their grade.
I'm able to successfully get the term table to show, but I'm having no luck getting the course table to show. I'm hoping it's not a case of "you can't nest a table within a table within a table", but I can't figure out how to make it stick, although I'm pretty sure it has to do with the "details-control" class...
Here is a link to a fiddle I put together showing what I have...any help finishing it up would be greatly appreciated!!
fiddle me this
var iTermGPACounter = 1;
$(document).ready(function() {
loadDetailsByCourse();
});
function loadDetailsByCourse() {
var table = $('#msGrades').DataTable({
data: [{
"__type": "DMC.WebServices.detailGPA",
"schoolYearLabel": "14-15",
"schoolLevel": "02",
"location": "Highland",
"grade": "7",
"gpaValue": "3.119",
"termGPA": [{
"term": "1",
"gpaValue": "3.857",
"termCourseGrades": [{
"courseNo": "38929712",
"sectionNo": "200",
"courseName": "HEALTH 2",
"letterGrade": "A+",
"department": "EL"
}, {
"courseNo": "32320711",
"sectionNo": "10",
"courseName": "LANG ARTS 2",
"letterGrade": "A+",
"department": "EL"
}, {
"courseNo": "32720711",
"sectionNo": "10",
"courseName": "MATH 2",
"letterGrade": "B",
"department": "MA"
}]
}, {
"term": "2",
"gpaValue": "3.714",
"termCourseGrades": [{
"courseNo": "38929712",
"sectionNo": "200",
"courseName": "HEALTH 2",
"letterGrade": "A",
"department": "EL"
}, {
"courseNo": "32320711",
"sectionNo": "10",
"courseName": "LANG ARTS 2",
"letterGrade": "A",
"department": "EL"
}, {
"courseNo": "32720711",
"sectionNo": "10",
"courseName": "MATH 2",
"letterGrade": "A-",
"department": "MA"
}]
}]
}, {
"__type": "DMC.WebServices.detailGPA",
"schoolYearLabel": "15-16",
"schoolLevel": "02",
"location": "Highland",
"grade": "8",
"gpaValue": "3.123",
"termGPA": [{
"term": "1",
"gpaValue": "3.143",
"termCourseGrades": [{
"courseNo": "32320711",
"sectionNo": "12",
"courseName": "LANG ARTS 2",
"letterGrade": "A",
"department": "EL"
}, {
"courseNo": "32720711",
"sectionNo": "12",
"courseName": "MATH 2",
"letterGrade": "D",
"department": "MA"
}]
}]
}],
paging: false,
columns: [{
className: 'details-control',
orderable: false,
data: null,
defaultContent: '<img src="http://i.imgur.com/SD7Dz.png">'
}, {
data: "schoolYearLabel"
}, {
data: "grade"
}, {
data: "location"
}, {
data: "gpaValue"
}],
order: [
[1, 'asc']
]
});
// Add event listener for opening and closing details
$('#msGrades tbody').on('click', 'td.details-control', function() {
var tr = $(this).closest('tr');
var row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
} else {
// Open this row
row.child(formatTermGPA(iTermGPACounter)).show();
tr.addClass('shown');
var oInnerTable = $('#termGPA_' + iTermGPACounter).dataTable({
data: row.data().termGPA,
paging: false,
searching: false,
columns: [{
className: 'details-control',
orderable: false,
data: null,
defaultContent: '<img src="http://i.imgur.com/SD7Dz.png">'
}, {
data: "term"
}, {
data: "gpaValue"
}],
order: [
[1, 'asc']
]
});
// Add event listener for opening and closing details
$('#termGPA_' + iTermGPACounter + ' tbody').on('click', 'td.details-control', function() {
var tr = $(this).closest('tr');
var row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
} else {
// Open this row
row.child(formatTermCourseGrades()).show();
tr.addClass('shown');
}
});
iTermGPACounter += 1;
}
});
}
function formatTermGPA(table_id) {
return '<table class="table table-striped" id="termGPA_' + table_id + '">' +
'<thead><tr><th></th><th>Term #</th><th>Term GPA</th></tr></thead></table>';
}
function formatTermCourseGrades() {
return '<table class="table table-striped" id="termCourseGrades">' +
'<thead><tr><th>Course Name</th><th>Letter Grade</th></tr></thead><tr><td>Math</td><td>B+</td></tr></table>';
}
I posted this question in the DataTables forum as well and received an answer...in a nutshell, as a starting point I copied from the DataTables examples a table with a single child table. When I added the second child table, I didn't think to rename the variables, so it kept calling back to the parent table :(. Below is a working fiddle of the final result:
working fiddle
function loadDetailsByCourse() {
$.ajax({
type: "POST",
contentType: "application/json; charset=UTF-8",
url: "WebServices/myStudentProfile.asmx/getDetailsByCourse",
data: JSON.stringify({ pageID: pageID }),
dataType: "json",
cache: false,
success: function (response) {
gpa = response.d;
var yearTable = $('#msGrades').DataTable({
paging: false,
data: gpa,
columns: [
{
className: 'term-details-control openClose',
orderable: false,
data: null,
defaultContent: ''
},
{ data: "schoolYearLabel" },
{ data: "grade" },
{ data: "location" },
{ data: "gpaValue" }
],
order: [[1, 'asc']]
});
// Add event listener for opening and closing details
$('#msGrades tbody').on('click', 'td.term-details-control', function () {
var tr = $(this).closest('tr');
var row = yearTable.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child(formatTermGPA(iTermGPACounter)).show();
tr.addClass('shown');
var termTable = $('#termGPA_' + iTermGPACounter).DataTable({
data: row.data().termGPA,
paging: false,
searching: false,
columns: [
{
className: 'course-details-control openClose',
orderable: false,
data: null,
defaultContent: ''
},
{ data: "term" },
{ data: "gpaValue" }
],
order: [[1, 'asc']]
});
// Add event listener for opening and closing details
$('#termGPA_' + iTermGPACounter + ' tbody').on('click', 'td.course-details-control', function () {
var tr = $(this).closest('tr');
var closestTable = tr.closest("table");
var row = closestTable.DataTable().row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child(formatTermCourseGrades(iCourseCounter)).show();
tr.addClass('shown');
var courseTable = $('#courseGrades_' + iCourseCounter).DataTable({
data: row.data().termCourseGrades,
paging: false,
searching: false,
columns: [
{ data: "courseName" },
{ data: "letterGrade" }
],
order: [[1, 'asc']]
});
}
iCourseCounter += 1;
});
iTermGPACounter += 1;
}
});
}
})
}
function formatTermGPA(table_id) {
return '<table class="table table-striped" id="termGPA_' + table_id + '">' +
'<thead><tr><th></th><th>Term #</th><th>Term GPA</th></tr></thead></table>';
}
function formatTermCourseGrades(table_id) {
return '<table class="table table-striped" id="courseGrades_' + table_id + '">' +
'<thead><tr><th>Course Name</th><th>Letter Grade</th></tr></thead></table>';
}

Formfield value from Webservice in Sencha touch

In my Sencha touch application, I am populating my container by creating form items dynamically from a json object.
For a textfield I'm using the code as below:
Ext.getCmp('mytestpanel').add({
xtype: response.screens[index].screenItems[i].xtype,
id:response.screens[index].screenItems[i].name,
label: response.screens[index].screenItems[i].title,
name: response.screens[index].screenItems[i].name
}
});
The json used:
{
"screens": [
{
"screenname": "Screen 1",
"screenItems": [
{"xtype": "textfield", "title": "Temperature"," name": "textfield1", "value":"service211"},
{"xtype": "button", "title": "Update", "name": "button1"}
]
},
{
"screenname": "Screen 2",
"screenItems": [
{"xtype": "emailfield", "title": "screen2"," name": "textfield2"},
{"xtype": "checkboxfield", "title": "label3", "name": "textfield13"},
{"xtype": "selectfield", "title": "Submit", "name": "button11"}
]
}
]
}
I need to update the value of this text field by using a webservice as seen in the json
{"xtype": "textfield", "title": "Temperature"," name": "textfield1", "value":"someservice211"}
As the values will be in real time, how am I supposed to do this?
What about using a store for reading the json? you could setInterval to store.load() and then add/edit the dynamic items on the load callback:
proxy: {
type: 'ajax',
url: 'http://URL',
reader: {
type: 'json',
rootProperty: 'screens'
}
},
autoLoad: true,
listeners: {
initialize: function() {
var interval = setInterval(function() {
Ext.StoreMgr.lookup('myStore').load();
}, 2000);
},
load: function(st) {
var testPanel = Ext.getCmp('mytestpanel');
Ext.each(st, function(record) {
var obj = Ext.getCmp(record.get('id'));
if (obj) {
if (record.get('value')) obj.setValue(record.get('value'));
} else {
testPanel.add({
xtype: record.get('xtype'),
id: record.get('id'),
label: record.get('label'),
name: record.get('name'),
value: record.get('value')
});
}
}
}
}
hope it helps-