I have created a saved search and filtering report for header and child record and i have pushed
var parseDataObj = {};
if (!parseDataObj[internalid]) {
parseDataObj[internalid] = {
account: account,
taxtotal: taxtotal,
subtotal: subtotal,
nameVendor: nameVendor,
amontNew: amontNew,
internalid: internalid,
data_irp: [
{
item: item,
kemasanItem: kemasanItem,
cartonIRBar: cartonIRBar,
diskon1Ir: diskon1Ir,
bonusCarton: bonusCarton,
bonusPcs: bonusPcs,
docNumIr: docNumIr,
},
],
};
} else {
parseDataObj[internalid].data_irp.push({
item: item,
kemasanItem: kemasanItem,
cartonIRBar: cartonIRBar,
diskon1Ir: diskon1Ir,
bonusCarton: bonusCarton,
bonusPcs: bonusPcs,
docNumIr: docNumIr,
});
}
var parseDataArr = [];
if (Object.keys(parseDataObj).length > 0) {
Object.keys(parseDataObj).map(function (key, index) {
parseDataArr.push(parseDataObj[key]);
});
}
log.debug("parse data ARR", parseDataArr);
and i have log.debug and data match to what i want. when i get record from taxtotal and it worked, but when i get data in the data_irp have error
if (parseDataArr.length > 0) {
for (var j = 0; j < parseDataArr.length; j++) {
xmlString +=
"<Row>" +
'<Cell ss:StyleID="MyAlign" ss:MergeAcross="0"><Data ss:Type="String"> ' +
parseDataArr[j].taxtotal +
"</Data></Cell>" +
"</Row>"; //its worked
if (parseDataArr.data_irp.length > 0) {
for (var k = 0; k < parseDataArr.data_irp.length; k++) {
// length undef (?)
xmlString +=
"<Row>" +
'<Cell ss:StyleID="MyAlign" ss:MergeAcross="0"><Data ss:Type="String"> </Data></Cell>' +
'<Cell ss:StyleID="MyAlign" ss:MergeAcross="3"><Data ss:Type="String"> ' +
parseDataArr.data_irp[k].item +
"</Data></Cell>" + //got error
"</Row>";
}
}
}
}
would you please help me for this error. thanks
Related
How can I get Blogger to display random posts, while preventing an infinite loop when there are no posts to display?
Here is my JavaScript code which I am attempting to use:
<script>
var dt_numposts = 10;
var dt_snippet_length = 100;
var dt_info = 'true';
var dt_comment = 'Comment';
var dt_disable = '';
var dt_current = [];
var dt_total_posts = 0;
var dt_current = new Array(dt_numposts);
function totalposts(json) {
dt_total_posts = json.feed.openSearch$totalResults.$t
}
document.write('<script type=\"text/javascript\" src=\"/feeds/posts/summary?max-results=100&orderby=published&alt=json-in-script&callback=totalposts\"><\/script>');
function getvalue() {
for (var i = 0; i < dt_numposts; i++) {
var found = false;
var rndValue = get_random();
for (var j = 0; j < dt_current.length; j++) {
if (dt_current[j] == rndValue) {
found = true;
break
}
};
if (found) {
i--
} else {
dt_current[i] = rndValue
}
}
};
function get_random() {
var ranNum = 1 + Math.round(Math.random() * (dt_total_posts - 1));
return ranNum
};
function random_list(json) {
a = location.href;
y = a.indexOf('?m=0');
for (var i = 0; i < dt_numposts; i++) {
var entry = json.feed.entry[i];
var dt_posttitle = entry.title.$t;
if ('content' in entry) {
var dt_get_snippet = entry.content.$t
} else {
if ('summary' in entry) {
var dt_get_snippet = entry.summary.$t
} else {
var dt_get_snippet = "";
}
};
dt_get_snippet = dt_get_snippet.replace(/<[^>]*>/g, "");
if (dt_get_snippet.length < dt_snippet_length) {
var dt_snippet = dt_get_snippet
} else {
dt_get_snippet = dt_get_snippet.substring(0, dt_snippet_length);
var space = dt_get_snippet.lastIndexOf(" ");
dt_snippet = dt_get_snippet.substring(0, space) + "
";
};
for (var j = 0; j < entry.link.length; j++) {
if ('thr$total' in entry) {
var dt_commentsNum = entry.thr$total.$t + ' ' + dt_comment
} else {
dt_commentsNum = dt_disable
};
if (entry.link[j].rel == 'alternate') {
var dt_posturl = entry.link[j].href;
if (y != -1) {
dt_posturl = dt_posturl + '?m=0'
}
var dt_postdate = entry.published.$t;
if ('media$thumbnail' in entry) {
var dt_thumb = entry.media$thumbnail.url
} else {
dt_thumb = "https://blogspot.com/"
}
}
};
document.write('<img alt="' + dt_posttitle + '" src="' + dt_thumb + '"/>');
document.write('<div>' + dt_posttitle + '</div>');
if (dt_info == 'true') {
document.write('<span>' + dt_postdate.substring(8, 10) + '/' + dt_postdate.substring(5, 7) + '/' + dt_postdate.substring(0, 4) + ' - ' + dt_commentsNum) + '</span>'
}
document.write('<div style="clear:both"></div>')
}
};
getvalue();
for (var i = 0; i < dt_numposts; i++) {
document.write('<script type=\"text/javascript\" src=\"/feeds/posts/summary?alt=json-in-script&start-index=' + dt_current[i] + '&max-results=1&callback=random_list\"><\/script>')
};
</script>
Expected output:
?
Actual output:
?
It looks like your post is mostly code; please add some more details.
It looks like you're trying to populate dt_current with dt_numposts = 10 elements. I modified getvalue() as follows, so that dt_numposts is capped at dt_total_posts, which may be 0. This allows the outer for loop to exit.
function getvalue() {
dt_numposts = (dt_total_posts < dt_numposts) ? dt_total_posts : dt_numposts;
// ...
I couldn't test this, because I don't have an example /feeds/posts/summary?max-results=100&orderby=published&alt=json-in-script&callback=totalposts JSON resource, but it works for zero posts. Whether is works for dt_numposts > 0, you'll need to test!
function reworkInfoData(jsonData){
var userData = [];
userData[0] = {
date: ' ',
data: []
};
userData[0].data[0] = {
activity: ' ',
time: ' '
}
var timeVar = new Date();
for(var i = 0; i < jsonData.length; i++){
timeVar = new Date(jsonData[i].date);
userData[i].date = timeVar.getFullYear() + '.' + timeVar.getMonth() +
'.' + timeVar.getDay();
for(var k = 0; k < jsonData[i].data.length; k++){
userData[i].data[k] = jsonData[i].data[k];
}
}
return UserData;}
I'm learning node.js, and for studiyng purposes im trying to write something like study loger using express and ejs. This block of code higher was used to rewrite the JSON date string to the pretty looking one. And i keep getting an error
TypeError: Cannot set property 'date' of undefined
at
userData[i].date = ...
Lot of things are wrong/bad practise the way you have done this.
1.Instead of code below:
var userData = [];
userData[0] = {
date: ' ',
data: []
};
Try:
var userData = [];
userData.push({
date: ' ',
data: []
});
2.You are checking for jsonData value in : for(var i = 0; i < jsonData.length; i++) but you are accessing userData with the iterator. userData[i].date this will fail when userData.length is lesser than jsonData.length. Change your logic to fix this.
Your userData array initially has only one object, so if your jsonData has length more than one than, you will get this error since userData[1] or so on is not defined
Try this
function reworkInfoData(jsonData){
var userData = [];
userData[0] = {
date: ' ',
data: []
};
userData[0].data[0] = {
activity: ' ',
time: ' '
}
var timeVar = new Date();
for(var i = 0; i < jsonData.length; i++){
timeVar = new Date(jsonData[i].date);
if(userData[i]) {
userData[i].date = timeVar.getFullYear() + '.' + timeVar.getMonth() +
'.' + timeVar.getDay();
for(var k = 0; k < jsonData[i].data.length; k++){
if(userData[i].data[k]) {
userData[i].data[k] = jsonData[i].data[k];
}else {
userData[i].data.push(jsonData[i].data[k])
}
}
} else {
var tmp = {};
tmp.date = timeVar.getFullYear() + '.' + timeVar.getMonth() +
'.' + timeVar.getDay();
for(var k = 0; k < jsonData[i].data.length; k++){
tmp[i].data.push(jsonData[i].data[k]);
}
}
}
return UserData;
}
I have some trouble with my project,
I need to build a game : Mine Sweeper,
My main problem in this project is that I have dynamic table in my html page
that I build that matrix in my Javascript page,
I want to get the current cell I pushed it by onclick event and I only got the first cell (0,0):
It's my home work project , I only need help to understand how can I get the index of each cell I`ve been clicked on ,
my html page :
<body onload="initGame()">
<header>
<h1>My Mine Sweeper</h1>
</header>
<table class="mineTable" onclick="cellClicked(this)" border="1">
<tbody class="mineSweeperTable" ></tbody>
</table>
my javascript Page :
'use strict';
var gMINE = '❉';
var gCELL = ' ';
var gLevel = {
SIZE : 4 ,
MINES: 0.2
};
var gCell ={
i : 0 ,
j : 1
}
var gMineSweeper = [];
function getRandomCell() {
return (Math.random() > gLevel.MINES)? gCELL : gMINE ;
}
function initGame() {
buildBoard();
renderBoard(gMineSweeper);
countMines(gMineSweeper);
//setMinesNeighborsCount(gMineSweeper);
}
function buildBoard() {
var elCell = document.querySelectorAll ('td');
for (var i = 0; i < gLevel.SIZE; i++) {
gMineSweeper.push([]);
for (var j = 0; j < gLevel.SIZE; j++) {
gMineSweeper[i][j] = getRandomCell();
}
}
}
function renderBoard(board) {
var elMineSweeperTable = document.querySelector('.mineSweeperTable');
var strHTML = '';
board.forEach(function (row) {
strHTML += '<tr>';
row.forEach(function (cell) {
strHTML += '<td> ' + cell + ' </td>'
});
strHTML += '</tr>'
})
elMineSweeperTable.innerHTML = strHTML;
}
function countMines(board) {
var count = 0;
board.forEach(function(row) {
row.forEach(function(cell) {
if(cell === gMINE){
count++;
}
});
});
console.log('Mines Count : ' , count);
return count;
}
function cellClicked(elCell,i,j) {
var elCell = document.querySelectorAll ('td');
console.log('You Clicked on me ! : ' , elCell,i,j);
debugger;
}
function setMinesNeighborsCount(board) {
var elCell = document.querySelector('td');
// debugger;
// for (var i = 0; i < board; i++) {
// gMineSweeper.push([]);
// for (var j = 0; j < board; j++) {
// var ngbrsCount = countNgbrs(i, j);
// console.log('Cell ', i, ', ', j, ' has: ', ngbrsCount );
// if (ngbrsCount > 0) {
// debugger;
// board.push(ngbrsCount);
// // elCell.innerHTML = ngbrsCount;
// cell[i][j] = ngbrsCount;
// elCell = cell[i][j];
// }
// // debugger;
// if (cell === gMINE) {
// console.log('This cell is Mine', i, j);
// // debugger;
// // board.push(ngbrsCount);
// }
// }
// }
var c = elCell;
debugger;
board.forEach(function (row, i) {
row.forEach(function (cell, j) {
var ngbrsCount = countNgbrs(i, j);
console.log('Cell ', i, ', ', j, ' has: ', ngbrsCount );
if (ngbrsCount > 0) {
//board.push(ngbrsCount);
// elCell.innerHTML = ngbrsCount;
//debugger;
c[i][j] = ngbrsCount;
}
debugger;
if (cell === gMINE) {
console.log('This cell is Mine', i, j);
//debugger;
// board.push(ngbrsCount);
}
});
});
}
function countNgbrs(i, j) {
var count = 0;
for (var a = i-1; a <= i+1; a++){
if ( a < 0 || a >= gMineSweeper.length ) continue;
for (var b = j-1; b <= j+1; b++){
if ( b < 0 || b >= gMineSweeper.length ) continue;
if ( a === i && b === j ) continue;
if (gMineSweeper[a][b] === gMINE) count++;
}
}
return count;
}
To get the postion of the from table tag using jQuery
HTML
<td onclick='Getposition($(this))'></td>
function Getposition(e){
var col = e.index() + 1;
var row = e.closest('tr').index() + 1;
alert( [col,row].join(',') );
}
Example Fiddle
http://jsbin.com/lupifilike/2/edit?html,js,output
function cellClicked(el) {
document.querySelector('.mineTable').onclick = function(){
var el = event.target;
console.log('td clicked' , el);
debugger;
if(el.innerText === gMINE){
console.log('Game Over! ');
}
};
}
its working that way :)
I have a json file with a list of users and points. I want to somehow Loop through until the _id == userId, then count how many objects there are to get their position.
So far I have this json file which has the points in desc order already
[
{
"_id":"55db8684ce3bf55b4b612a72",
"firstname":"Billy",
"lastname":"Bob",
"points":3109373
},
{
"_id":"55dbdffeaba8ee274d3b9f89",
"firstname":"Steve",
"lastname":"Jones",
"points":34434
},
{
"_id":"55dbdbf756b0fa064dd3e507",
"firstname":"Jim",
"lastname":"Kirk",
"points":1000
},
{
"_id":"55dbdc2756b0fa064dd3e508",
"firstname":"Casey",
"lastname":"Jones",
"points":36
},
{
"_id":"55dbdbd656b0fa064dd3e506",
"firstname":"Reg",
"lastname":"Barclay",
"points":33
},
]
What I need to do is find the position for the user using their ID. So far I have but the position always returns undefined.
$.each(obj, function(index, value) {
var returnObj = (this === "<%= user._id %>");
var position = returnObj.length;
console.log('user position is ' + position);
});
But this always returns undefined 11 times, which is what the position should be.
If I got you right, using for instead of each works which is much faster and not much to code.
try this,
for(var i =0;i < obj.length; i++)
{
if(obj[i]['_id'] == "55dbdc2756b0fa064dd3e508"){
alert('position :' + parseInt(i + 1)); //<--position in an obj
alert('index :' + i); //<----actual index
break;
}
}
var obj=[
{
"_id":"55db8684ce3bf55b4b612a72",
"firstname":"Billy",
"lastname":"Bob",
"points":3109373
},
{
"_id":"55dbdffeaba8ee274d3b9f89",
"firstname":"Steve",
"lastname":"Jones",
"points":34434
},
{
"_id":"55dbdbf756b0fa064dd3e507",
"firstname":"Jim",
"lastname":"Kirk",
"points":1000
},
{
"_id":"55dbdc2756b0fa064dd3e508",
"firstname":"Casey",
"lastname":"Jones",
"points":36
},
{
"_id":"55dbdbd656b0fa064dd3e506",
"firstname":"Reg",
"lastname":"Barclay",
"points":33
},
]
for(var i =0;i < obj.length; i++)
{
if(obj[i]['_id'] == "55dbdc2756b0fa064dd3e508"){
alert('position :' + parseInt(i + 1));
alert('index :' + i);
break;
}
}
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
});