#CanvasLMS JQuery help needed (More of a Jquery question)
80 messages · Page 1 of 1 (latest)
async function getStudents() : Promise<User[]>{
var studentList: User[] = [];
var something = getAll($.get, "users", { 'enrollment_type[]': 'student' });
console.log("This is the result of the getAll: " + something);
return studentList;
}```
this is currently my function, and I don't really understand how to store it into studentList
the only thing that returns from the getAll is quite literally object Object
don't use var. At all.
What is getAll(…)?
don't use jQuery either. can only assume you need to await getAll()
getAll is canvas's implementation to get all of something from a class
in this circumstance, I'm getting every user that matches the student type enrollment
yes, but what's its signature?
(alias) getAll(verb: HandleResult, url: string, options: object): JQueryPromise<any>
dafuq is a JQueryPromise... anyway. Put await before the getAll
in simple terms, basically just a guarantee something will return from your jquery statement lol
that was part of the fix, can't believe i missed that
this is now the resulting console log
simple sounding quesiton but I've really just never done it, how would I go about adding these objects individually as options in a dropdown menu?
console.log('this is the result', something);
<div class="select-student">
<button class="dropdown" id="select">Select Student</button>Selected student: <span id="selected-student"></span>
<div id="actual-dropdown" class="student-list">
<p>test</p>
</div>
</div>```
the menu in question
Agoknee, should we notify P35 that we found one of his 34 brothers?
oh lord
am i similar to a known member of the server lol
usually that's not a fantastic sign 😆
in this case, you should feel honored. surely you aren't worthy
bahaha
i worded my question poorly
I meant to ask like
how would I sequentially add them? add each student as an option? wouldn't the thing you posted just post one option with all the students?
perhaps im being dumb
or I am used to having fight every step of the way to get canvas to cooperate
for..of and the link he provided
yes, iterate over the array using
for (const student of students) {
// add one option here
}
thank you. that's an easy answer but unfortunately im used to being barred from using for loops
my school's standards are... weird
wait
dafaq?
must use jQuery and can't use a for loop??
alternatively couldn't I map through the get all result?
because it's an array of objects
my school discouraged the use of for loops and encouraged mapping instead
map() should not have side-effects. theoretically you could map to elements and append those, but it's an odd choice
your school is terrible
bahahah
classic for loops and for..of should be used almost-exclusively (when you need side-effects)
o7
maybe you misunderstood your teacher. In the following case, .map should be preferred over loops:
// meh
const result = []
for (const x of xs) {
result.push(f(x))
}
// better
const result = xs.map(x => f(x))
but loops are not inherently bad and sometimes even more up to the task than .map.
no. like for an entire class you would get points off for using for loops after map was introduced
i sincerely wish i was joking. caused many hours of frustration
then go to another school. They obviously can't teach you anything of value.
Alternatively feel free to send your teacher here, so we can kick their ass.
hahaha
well as im about to enter my last semester it's a bit late for that
hm. perhaps im misunderstanding?
async function getStudents(){
var studentList = await getAll($.get, "users", { 'enrollment_type[]': 'student' });
for (const student of studentList){
document.getElementById("actual-dropdown").add(student)
}
//console.log("This is the result of the getAll: " + something);
}```
<div class="select-student">
<button class="dropdown" id="select">Select Student</button>Selected student: <span id="selected-student"></span>
<div id="actual-dropdown" class="student-list">
<p>test</p>
</div>
</div>```
it is both complaining in document.getElementById("actual-dropdown") that object could be null
and then it says that HTML element doesn't have .add?
answered my own question. I tried to make code shorter but missed the point
double nvm
still same errors
const studentList = await getAll($.get, "users", { 'enrollment_type[]': 'student' });
const dropdownlocation = document.getElementById("actual-dropdown");
var option = document.createElement("option");
for (const student of studentList){
option.text = student;
dropdownlocation.add(option);
}```
i fixed that part
this is now the inner of the function
fixed the object could be null part
still getting and stuck on Property 'add' does not exist on type 'HTMLElement'.
looked up fixes and they only seemed to be in situations where someone was trying to store an input into a variable, so I'm not entirely sure what to do here
then you are likely selecting the wrong element. HTMLElement does not feature .add. But HTMLSelectElement does.
<select id="actual-dropdown" class="student-list">
<option>test</option>
</select>```
that's what I am supposedly selecting
does it not like that it's within a div?
oh wait I know why it's upset
so because canvas is in fact a bitch
you can't just throw in raw html, you have to make consts to inject into the website as html
so since it's not looking directly at html code, it's not recognizing the fact that it's in a const
so it's never gonna not think it's just a htmlelement