Forum Discussion
JohnBarulich1
7 years agoQrew Cadet
Dan:
Thanks a bunch, this helped me a ton with how to start and what I need to learn. A few comments/questions about the syntax/logic. Feel free to let me know anything about my thought process here:
1. I understand we need to create an anonymous function for the .each() call so that we can loop through every record and retrieve its attributes
2. I understand what get() conceptually should do. The dbidTable needs to be referenced on every iteration of the each() loop
3. The .then() is a promise to be fulfilled if the get() call is successful. However, what value is stored into 'xml' from get() if it's successful. And WHY do we need to pass 'xml' to our selection along with record? Why are double quotes allowed, when the literature I have read for this requires single quotes?
4. Can you briefly explain the necessity for the 'this' keyword in the selection. I have used it plenty, but maybe there are subtleties I don't quite understand in this statement.
Thanks again, I have learned quite a bit so far.
Thanks a bunch, this helped me a ton with how to start and what I need to learn. A few comments/questions about the syntax/logic. Feel free to let me know anything about my thought process here:
1. I understand we need to create an anonymous function for the .each() call so that we can loop through every record and retrieve its attributes
2. I understand what get() conceptually should do. The dbidTable needs to be referenced on every iteration of the each() loop
3. The .then() is a promise to be fulfilled if the get() call is successful. However, what value is stored into 'xml' from get() if it's successful. And WHY do we need to pass 'xml' to our selection along with record? Why are double quotes allowed, when the literature I have read for this requires single quotes?
4. Can you briefly explain the necessity for the 'this' keyword in the selection. I have used it plenty, but maybe there are subtleties I don't quite understand in this statement.
Thanks again, I have learned quite a bit so far.
_anomDiebolt_
7 years agoQrew Elite
I should have included the URL of the table in my reply:
https://login.quickbase.com/db/6ewwzuuj?a=td
You should visit this URL, press F12 and paste my code into the console.
As to your questions:
1. I understand we need to create an anonymous function for the .each() call so that we can loop through every record and retrieve its attributes
You don't normally think in terms of looping each record - rather you perform functional methods such as map(), filter(), reduce(), each() on the selection.
2. I understand what get() conceptually should do. The dbidTable needs to be referenced on every iteration of the each() loop
dbidTable is a relative URL which is just the dbid for the table you are accessing. The $.get() returns an XML document. The following statement selects each <record> in the XML response and processes it:
$("record", xml).each(function() {...}
3. The .then() is a promise to be fulfilled if the get() call is successful. However, what value is stored into 'xml' from get() if it's successful. And WHY do we need to pass 'xml' to our selection along with record? Why are double quotes allowed, when the literature I have read for this requires single quotes?
XML holds the response body of the GET request. If you expand the #document in the console you can see the XML response:
The double quotes are just placed around JavaScript strings. I think your reference to single quotes in the documentation is in forming query clauses which QuickBase documents like this:
{'3'.EX.'123'}
Why QuickBase does this I don't know because you don't need the single quotes.
4. Can you briefly explain the necessity for the 'this' keyword in the selection. I have used it plenty, but maybe there are subtleties I don't quite understand in this statement.
In my code this refers to the individual record being processed by the function inside the each method:
https://login.quickbase.com/db/6ewwzuuj?a=td
You should visit this URL, press F12 and paste my code into the console.
As to your questions:
1. I understand we need to create an anonymous function for the .each() call so that we can loop through every record and retrieve its attributes
You don't normally think in terms of looping each record - rather you perform functional methods such as map(), filter(), reduce(), each() on the selection.
2. I understand what get() conceptually should do. The dbidTable needs to be referenced on every iteration of the each() loop
dbidTable is a relative URL which is just the dbid for the table you are accessing. The $.get() returns an XML document. The following statement selects each <record> in the XML response and processes it:
$("record", xml).each(function() {...}
3. The .then() is a promise to be fulfilled if the get() call is successful. However, what value is stored into 'xml' from get() if it's successful. And WHY do we need to pass 'xml' to our selection along with record? Why are double quotes allowed, when the literature I have read for this requires single quotes?
XML holds the response body of the GET request. If you expand the #document in the console you can see the XML response:
The double quotes are just placed around JavaScript strings. I think your reference to single quotes in the documentation is in forming query clauses which QuickBase documents like this:
{'3'.EX.'123'}
Why QuickBase does this I don't know because you don't need the single quotes.
4. Can you briefly explain the necessity for the 'this' keyword in the selection. I have used it plenty, but maybe there are subtleties I don't quite understand in this statement.
In my code this refers to the individual record being processed by the function inside the each method:
$("record", xml).each(function() {
var rid = $("record_id_", this).text();
var name = $("function_name", this).text();
var type = $("result_type", this).text();
console.log(rid, name, type);
});