var idd ;
var subjects = [];
var ctr = 0;
var teacher = $('#selectTeacher option:selected').text();
for(var j = 0 ; j < lstClasses.length ; j++)
{
var sub = {};
var key = lstClasses[j];
for(var i = 0 ; i < lstSubjects.length ; i++)
{
var id = lstClasses[j] + lstSubjects[i];
var cls = $('#'+id).attr('class');
if(cls.indexOf('tickimage') >= 0)
{
if(ctr == 0)
{
var val = [];
}
ctr = ctr + 1;
idd = id.replace(lstClasses[j], "");
val.push(idd);
/* console.log(val); */
sub[key] = val;
}
/* console.log(sub); */
subjects.push(sub);
}
}
the data that i'm sending is not going to backend properly in the json format.i just want to send particular class data and its subjects but when sending the data its not going properly
Related
how to do multiple loops and display data as shown in the picture
I have data in the form of an array and I want to loop it so that it looks like this picture
enter image description here
here's my script
var pf_lookup = {};
var pf_item_name = [];
var pf_item_code = [];
var pf_lot = [];
var pf_pdo_item = [];
var pf_item_process = [];
for (var itemdtl, i = 0; itemdtl = data[i++];) {
//console.log(itemdtl);
var item_name = itemdtl.ITEM_NAME;
var item_code = itemdtl.ITEM_CODE;
var greige_num = itemdtl.GREIGE_NUM;
var lot = itemdtl.LOT;
var item_process = itemdtl.ITEM_PROCESS;
if (!(item_code in pf_lookup)) {
pf_lookup[item_code] = 100;
pf_item_name.push(item_name);
pf_item_code.push(item_code);
pf_greige_num.push(greige_num);
pf_lot.push(lot);
pf_item_process.push(item_process);
}
}
$.each(pf_item_code, function (i, val) {
var itemQtyPack = 0;
var WeightPack = 0;
var WeightPackLot = '';
for (var j = 0; j < data.length; ++j) {
var pf_lookupx = {};
var pf_lotxx = [];
var item_codex = data[j]['ITEM_CODE']
var lotx = (data[j]['LOT'])
var item_name = data[j]['ITEM_NAME']
var greige_num = data[j]['GREIGE_NUM']
var netto = data[j]['NETTO']
if (pf_item_code[i] == data[j]['ITEM_CODE']) {
var lotArray = lotx.split(" ")
for (var k = 0; k < lotx.length; ++k) {
}
$.each(lotArray, function (i, val) {
for (var k = 0; k < data.length; ++k) {
if (pf_item_code[i] == data[k]['ITEM_CODE']) {
}
}
})
}
}
})
I've managed to get the item_code, but when looping lots it only shows 1 lot there should be 2 lots,
and after the lot is found then looping to get the list greige_num,
how ?
The second last loop condition, shouldn't it be
for (var k = 0; k < lotArray.length; ++k) { // code ...}
In google apps spreadsheet I am parsing json and filling up cells. After seting value to cell I check if the row has this value and if it does I go to the next cell and set new value, then I check the second value and so on. But something goes wrong and the if and else are both executing..
var customfields = SpreadsheetApp.openById('id').getSheetByName('Form').getRange('J25').getValue();
if (customfields == true) {
var jj = 2;
var ii = 1;
for each(item in data) {
var size = Object.keys(data[k].customfields).length;
if (size == 0) {
k = k + 1;
continue;
}
Logger.log(k)
for (j = 0; j < size; j++) {
var vl = data[k].customfields[j].value;
var nm = data[k].customfields[j].name;
var rng = SpreadsheetApp.openById('id').getSheetByName('Data').getMaxColumns();
for (var cn = 0; cn <= rng; cn++) {
var dat = sheet.getRange(1, cn).getValue();
Logger.log("IF STATEMENT")
if (dat == nm) {
sheet.getRange(ii, cn).setValue(nm);
} else {
sheet.getRange(ii, br).setValue(nm);
}
}
Logger.log(nm)
br = br + 1;
}
k = k + 1;
}
}
Hello i am trying to escape comma(,) in a string.and i am using split and join when i select multiple values.But in some cases within my selection i have comma(,) so it is considering that as different string.How i can escape comma in selection.
What i am trying is
$('#info').on('rowselect', function (event) {
var rows = $("#info").jqxGrid('selectedrowindexes');
var selectedvalue = new Array();
if (rows != "") {
for (var m = 0; m < rows.length; m++) {
var row = $("#info").jqxGrid('getrowdata', rows[m]);
selectedvalue [selectedvalue .length] = row;
}
var len = selectedvalue .length;
var data = "";
for (var i = 0; i < len; i++) {
data += selectedvalue[i].fieldvale +",";
}
var newStr = data.substring(0, data.length - 1);
var finalOutput = newStr.split(',');
var fieldvale = "" + finalOutput.join("','") + "";
GetGidbyplots($('#ddlIndustrialarea').find('option:selected').text(), fieldvale);
}
});
My selection values are like :'10','11','12','117,142&141'
My working Solution is
$('#info').on('rowselect', function (event) {
var rows = $("#info").jqxGrid('selectedrowindexes');
var selectedvalue = new Array();
if (rows != "") {
for (var m = 0; m < rows.length; m++) {
var row = $("#info").jqxGrid('getrowdata', rows[m]);
selectedvalue [selectedvalue .length] = row;
}
var len = selectedvalue .length;
var data = "";
for (var i = 0; i < len; i++) {
data += selectedvalue[i].fieldvale +":";
}
var newStr = data.substring(0, data.length - 1);
var finalOutput = newStr.split(':');
var fieldvale = "" + finalOutput.join("','") + "";
GetGidbyplots($('#ddlIndustrialarea').find('option:selected').text(), fieldvale);
}
});
I need to sort list strings under the table ,so for that i have written following lines of code but on console i am not getting any values:
var j = 9;
var rows = element.all(by.repeater('row in renderedRows'));
var column = element.all(by.repeater('col in renderedColumns'));
expect(rows.count()).toEqual(5); //here its printing number of rows
expect(column.count()).toEqual(5); //here its printing number of columns
var arr = [rows.count()];
for (var i = 0; i < rows.count(); i++) {
console.log("aai" + i);
if (i = 0) {
//var columnvalue=column.get(9).getText();
var columnvalue = column.get(9).getText().then(function(ss) {
return ss.trim();
arr[i] = ss.trim(); //here it will save the value first value of column
console.log("value1" + arr[i]);
expect(arr[i]).toEqual('DN');
console.log("aa" + ss.trim());
});
} else {
var j = j + 8;
var columnvalue = column.get(j).getText().then(function(ss) {
return ss.trim();
arr[i] = ss.trim(); //here it will save the other values of column
console.log("value" + arr[i]);
expect(arr[i]).toEqual('DN');
console.log("ab" + ss.trim());
});
}
}
Sorting_Under_Table: function(col){
test = [];
var m;
var dm = 0;
element(by.xpath('//div[#class="ngHeaderScroller"]/div['+col+']')).click();
element.all(by.repeater('row in renderedRows')).then(function(row) {
m = row.length;
for (i = 1; i <= row.length; i++)
{
user_admin_table_name = browser.driver.findElement(by.xpath('//div[#class="ngCanvas"]/div['+i+']/div['+col+']'));
user_admin_table_name.getText().then(function(text) {
var test_var1 = text.toLowerCase().trim();
test.push(test_var1);
var k = test.length
if (k == m){
for (j = 0; j < test.length; j++){
test.sort();
d=j+1;
user_admin_table_name1 = browser.driver.findElement(by.xpath('//div[#class="ngCanvas"]/div['+d+']/div['+col+']'));
user_admin_table_name1.getText().then(function(text1) {
var test_var2 = text1.toLowerCase().trim();
if (test_var2 == test[dm]){
expect(test_var2).toEqual(test[dm]);
dm = dm +1;
}else {
expect(test_var2).toEqual(test[dm]);
log.error("Sorting is not successful");
dm = dm +1;
}
});
}
}
});
}
});
},
You can use this code for sorting and verifying is it sorted or not
I'm not sure how your above example is doing any sorting, but here's a general solution for trimming and then sorting:
var elementsWithTextToSort = element.all(by.xyz...);
elementsWithTextToSort.map(function(elem) {
return elem.getText().then(function(text) {
return text.trim();
});
}).then(function(trimmedTexts) {
return trimmedTexts.sort();
}).then(function(sortedTrimmedTexts) {
//do something with the sorted trimmed texts
});
I am trying to re-populate a form from some values in localStorage. I can't quite manage the last part to get the loop to populate my name and values.
function loadFromLocalStorage() {
PROCESS_SAVE = true;
var store = localStorage.getItem(STORE_KEY);
var jsn = JSON.parse(store);
console.log(jsn);
if(store.length === 0) {
return false;
}
var s = jsn.length-1;
console.log(s);
for (var i = 0; i < s.length; i++) {
var formInput = s[i];
console.log(s[i]);
$("form input[name='" + formInput.name +"']").val(formInput.value);
}
}
Could I get some pointers please.
Your issue is in this section of code.
var s = jsn.length-1;
console.log(s);
for (var i = 0; i < s.length; i++) {
You are setting s to the length of the jsn array minus 1, then using it as if it were jsn. I think you intended something like this.
function loadFromLocalStorage() {
PROCESS_SAVE = true;
var store = localStorage.getItem(STORE_KEY);
var jsn = JSON.parse(store);
console.log(jsn);
if(store.length === 0) {
return false;
}
for (var i = 0; i < jsn.length; i++) {
var formInput = jsn[i];
console.log(jsn[i]);
$("form input[name='" + formInput.name +"']").val(formInput.value);
}
}