Closed frankcollins3 closed 1 year ago
fixed by redeclaring the @Model.PokemonSrc as a variable returned with @Html.Raw(Json.Serialize):
<script>
👍 var pokemonSrcBack = @Html.Raw(Json.Serialize(Model.PokemonSrcBack));
👍 var pokemonSrc = @Html.Raw(Json.Serialize(Model.PokemonSrc));
const pokemonIdFromSrc = (src) => {
if (typeof src === "string")
{
let srcId = src.replace(/\D+/g, '');
return srcId
} else
{
return;
}
}
const pokeMouseEnter = (event) => {
console.log('event', event);
let src = event.target.src;
let srcId = pokemonIdFromSrc(src);
$(event.target).attr('src', pokemonSrcBack[srcId - 1]);
}
const pokeMouseLeave = (event) => {
let src = event.target.src;
if (typeof src === "string")
{
let srcId = pokemonIdFromSrc(src);
$(event.target).attr('src', pokemonSrc[srcId - 1]);
} else
{
return;
}
}
const pokemonClick = (event) => {
console.log('event', event)
let src = event.target.src
let srcId = src.replace(/\D+/g, '');
console.log(src);
console.log(srcId);
}
</script>
attempting to do: access the Model created in the code-behind file, of which there are 3
public <list> string
created from the pokeAPI: 1 (pokemon.name) 2 (pokemon.sprites.front_default) // front facing img-src-data 3 (pokemon.sprites.back_default) // back facing img-src-dataerror:
proposed approach: 0: first approach includes accessing the
by index, determined by pokemonId // should also include [i] - 1 but still doesnt explain error.
possible improvements: