I have an attribute in my Ignicoes class called "Estado" this attribute is type enumerable. My question is, how I'm going to reference it in javascript? Here is my model:
public enum Estado
{
Aceite,
emAvaliacao,
Recusado
}
public class Ocorrencias
{
public Estado Estado { get; set; }
}
Here is the function on my index that I want to use:
function getData(id) {
$.get(`/api/IgnicoesAPI/${id}`, function (data) {
//o div terá que ser limpo para que a informação não seja subreposta
document.getElementById("myDiv").innerHTML = "";
document.getElementById("buttons").innerHTML = "";
document.getElementById("header").innerHTML = "";
document.getElementById("content").innerHTML = "";
//adição dos botões que alteram o estado da ignição
var desativo = "#808080";
//HERE IS WHERE I DON'T KNOW HOW TO ACCESS THE ENUMERABLE
if (data.estado == "aceite") {
//CODE
}
else {
//CODE
}
});
}
There is no enum
and public
keywords at use in Vanilla Javascript at the moment.
Note 2 in 11.6.2 at the official Ecma site says:
enum is not currently used as a keyword in this specification. It is a future reserved word, set aside for use as a keyword in future language extensions. Similarly, implements, interface, package, private, protected, and public are future reserved words in strict mode code.
You can maybe use a workaround like this:
var Estado = {
"Aceite": 0,
"emAvaliacao": 1,
"Recusado": 2
}
And use it like:
var firstEnumValue = Estado.Aceite;