$.getJSON("urlhere", {}, function(data)
{
// Other code is commented out, I'm just using the following loop to test.
for(var a = 0; a < 2546; a++)
if(a > 995)
alert((a + 1) + ": " + data.d.results[a].Column2);
});
For some reason, I wasn't getting all the things from my list that I needed. So I put in this loop to test it and it stops at 1000 for some reason. Why does this happen and how do I fix it?
SharePoint only returns 1000 results per "page." If you look, there should be a "link" element in there near the bottom of the JSON that contains a link to the next 1000 results.
That's how it is when it returns XML, anyway. Haven't tried JSON, but I'm sure it's similar.
'urlForListData' + '?$filter=Building eq \'' + building + '\''
I found out that you can filter the list for what you need so that it never exceeds 1000, which was much simpler than what I was doing before. Of course, Building is a column in the SharePoint list and building is a variable holding the requested building number.
Related
I am attempting to create barcodes that increment by 1 for an entered quantity and add each of them to a MongoDB collection.
I use db.controlNumber.insert({controlNumber}) to do this, and I also use
console.log(controlNumber) to see my result. However, in the database, the incremented number will go to the max and enter that many times, where the console.log shows it increment.
while (i < count) {
i++;
controlNumber.controlNumber = controlVar[0] + "-" + controlVar[1] + "-" +
controlVar[2] + "-" + controlVar[3] + "-000" + i;
db.controlNumber.insert(controlNumber);
console.log(controlNumber);
}
I expect my mongoDB collection to have control number (for example if user wants 5 control numbers)
a-b-c-d-001
a-b-c-d-002
...
a-b-c-d-005
Instead, it makes 5 entries of
a-b-c-d-005
You're mutating controlNumber.controlNumber. Instead, create a new object to insert:
const toInsert = Object.assign({}, controlNumber, { controlNumber: i });
db.controlNumber.insert(toInsert)
It'd likely also be worth either using async/await or promises to handle asynchronous calls. If you do await db.controlNumber.insert(controlNumber) you wouldn't have run into any problems because it would have waited for the document to be fully inserted before moving on to the next one.
This is the Code Sandbox: https://codesandbox.io/s/rw0j2orqmp
The file this is in is reducers.js
I'm building a React/Redux calculator app, and currently I'm in the process of making the output display the results of the current calculation held in state. It works without parentheses but calculates the whole formula rather than a piece at a time. To fix this I wanted to wrap each piece in parentheses to have it calculate separately, taking off the method and then sticking it back on when the first part is finished calculating by doing this:
value:
methods.indexOf(state.lastValue) < 0
? eval("(" + state.calc.slice(0, -1) + ")" + state.calc.slice(-1) + state.value)
: state.value,
but when I have it like that, I get "Unexpected token ) " .
Is there an easier way to accomplish what I'm trying to do, and or is there a functional replacement for eval() in this case?
I'm not sure why you're using eval or parentheses here. Is there a reason why this won't work for you?:
methods.indexOf(state.lastValue) < 0
? state.calc.slice(0, -1) + state.calc.slice(-1) + state.value
: state.value
If you need to group things together, just use parentheses without the eval.
methods.indexOf(state.lastValue) < 0
? ((state.calc.slice(0, -1)) + state.calc.slice(-1) + state.value)
: state.value
Update: I see what you're saying, sorry, it was hard to understand from your original explanation and I was on my mobile and couldn't really inspect your sandbox.
I'm thinking it may be better to keep a string that you can evaluate simply later, for example, if you have "7 + 3" stored and press *, turn wrap that original string in parentheses and add the *, resulting in "(7 + 3) *", etc. Then whenever you want to show the result, you just evaluate that single stored calculation.
If you insist on doing eval that way, I'll just tell you that it works. For example, try this in the console:
eval("(" + "7 + 3" + ")" + "* 2")
// 20
So you may be doing something wrong with the values you are returning from the slice, which results in an eval error.
Try console logging that whole expression to see what's actually going on.
I am working on a sheet that contains job description information, including an Overview and Responsibilities. The source data is not exact, but it roughly has the Overview in one cell of a column, and each Responsibility in additional cells in the same column. I am writing the Overview (which I am determining based on character count) in one results column, and building an unordered list with each the Responsibilities into another results column.
My source isn’t always perfect though. I have situations where the first Responsibility is included in the same cell as its corresponding Overview. I can recognize that by the text, and have an indexOf() statement written to do that.
When I use a slice() method, the script is correctly indicating the text that is occurring after the appropriate index. But what I need is to use the splice() method, so that I can remove that text from the source data before creating the results data. However, when I change the statement from slice() to splice(), I’m getting an error: “TypeError: Cannot find function splice in object {beginning text of the cell}”
for(i=0; i<data.length; i++) {
var iRow = data[i];
if(iRow[12].length > 250) { // this is an overview
if(iRow[12].indexOf("What you’ll do")>-1) { // is there a responsibility at the end of the overview?
var startIndex = iRow[12].indexOf("What you’ll do");
// this is the line that works for slice(), but not splice()
var txt = iRow[12].splice(startIndex, 26); // splice out the end of text, starting at the index.
data[writeRow][18] += iRow[12]; // write the overview, without the added responsibility
data[writeRow][19] += "<li>" + txt + "</li>"; // add the extracted responsibility to its list
} else { // these is no responsibility added to the end of the overview
data[writeRow][18] += iRow[12]; // write the overview
}
} else { // this is a responsibility
data[writeRow][19] += "<li>" + iRow[12] + "</li>"; // add it to the list
}
}
There's obviously a lot more going on (defining var data, var writeRow, initiating the , etc) which all works fine. I’m sure that I’m just being an idiot somewhere. But can someone help me figure out why slice() works here, but splice() doesn’t?
splice is an array function. slice is both, an Array function and a String function.
References
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
I need to take a textbox that is full of formatted info about accounts and then sort it somehow. I would like to know if it would be ideal (I'm trying to make this as efficient as possible) to parse the info into a two dimensional array, or if I should make account objects that will hold info in fields.
The program is simply meant to format the data so that it can be printed out without having to copy/paste.
So far I have...
function generateOutputfvoc()
{
var accountLines = document.getElementById('accountLines').value;
var accountLinesTemp = accountLines.split(/[\s]/);
for(var i = 0; i < accountLinesTemp.length; i++)
{
if(accountLinesTemp[i].match(/
Edit (1-18-13): Here is an example input. It is basically text copied from a web CRM tool. Note, this example input is something I typed up randomly.
P8B000001234567 stackoverflow Thing 12522225555 444 Active 2005-02-26 CO1000123456
P8B000001234568 stackoverflow Another Thing 444 Active 2005-02-26 CO1000123456
P8B000001234569 stackoverflow Another Thing 556 Active 2005-02-26 CO1000123456
I would like my program to take the text and simply output the text like this:
P8B000001234567 stackoverflow Thing 12522225555 444 Active 2005-02-26 CO1000123456
P8B000001234568 stackoverflow Another Thing 444 Active 2005-02-26 CO1000123456
P8B000001234569 stackoverflow Another Thing 556 Active 2005-02-26 CO1000123456
Also, I would like to know if I should use jQuery variables. I asked this because I have been looking online a lot and I found examples that use code that looks like this:
$check=fcompcheck();
if($check)
{
$output=document.frm1.type.value+" / ";
$output=$output+"Something - "+document.frm1.disco.value+" / ";
Note the: $output variable. The dollar sign indicates a jQuery variable, right?
Thank you for any help you might be able to offer me.
Update (1-19-13): I've taken a shot at it, but I'm making slow progress. I'm used to programming Java and my JavaScript looks too similar, I can tell I'm makings errors.
I'm taking it one step at a time. Here is the logic I'm using now.
Person pastes text into text box and pushes the generate button
Program takes the contents of the text box and parses it into a large array, removing only whitespace
Program then searches for patterns in the text and begins passing values into variables
I am trying to get the program to simply identify the pattern "Summary section collapse Name" because these four words should always be in this sequence. Once it identifies this it will pass the next two array values into first and last name variables. Here's some of the code:
var contactNameFirst, contactNameLast;
// Parse the input box into an array
var inputArr = document.getElementById('inputBox').value.split(/[\s]/);
for(var i = 0; i < inputArr.length; i++)
{
if(inputArr[i] == "Summary" && inputArr[i - 1] == "section" && inputArr[i - 2] == "Collapse" && inputArr[i + 1] == "Name")
{
if(inputArr[i + 2] != "Details")
{
contactNameFirst = inputArr[i + 2];
}
else
{
contactNameFirst = "";
}
if(inputArr[i + 3] != "Details")
{
contactNameLast = inputArr[i + 3];
}
else
{
contactNameLast = "";
}
}
}
document.getElementById('contactNameOutput').innerHTML = contactNameFirst + " " + contactNameLast;
Also, should I create a new post for this now, or keep editing this one?
Your accountLinesTemp is an Array of String, you could use the Array.sort function to sort your array as expected, and then use Array.join to get the full String if necessary.
See https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort on MDN for more information.
I know this is really basic but I am new to Javascript
This is a piece of code from a battleship game I am working on for a class
function displayMyBoats(ship){
for (var i = 0; i<ship.length; i++)
{
alert("ship.length = " + ship.length);
alert("Ship[i]= " + ship[i]);
document.getElementById( "Set_" + ship[i] ).src = fnImageShip;
alert("i = " + i);
}
}
I am testing with a ship array that is 5 elements. Everything works fine until it reaches 5, then all of a sudden it thinks the length of the array is 8.
There is no code to increase the length of ship array, so what would cause it to add to the length of the array?
The alerts are my testing to see what all the values are at.
To give you a hint, try adding an alert whenever your script is either entering or exiting the displayMyBoats(). Suddenly jumping to 8 indicates that it's entering the method a second time, this time with a ship of len 8.
Confirm or deny this theory by adding this alert after your for loop block:
alert('exiting displayMyBoats()');`
Perhaps you see more if you use console.log(ship); instead of alert(); - if you are using Firebug/Console.