简体   繁体   English

将图像添加到Array.push元素

[英]Add image to Array.push element

I am using select controls to cascade a filter selection going from league, team, to player. 我正在使用选择控件来级联从联赛,球队到球员的筛选器选择。 I was trying to add a player profile image to each player but I can't seem to add an img within an Array.push. 我试图向每个播放器添加播放器配置文件图像,但似乎无法在Array.push中添加img。 Any thoughts on how to render an image next to the player's name with the select control? 关于如何使用select控件在玩家名字旁边呈现图像的任何想法? I have the cascading filter setup for numerous values so I'm trying to not have to create new logic for the cascading select controls and their array of values if possible. 我具有用于多个值的级联过滤器设置,因此,如果可能的话,我试图不必为级联选择控件及其值数组创建新的逻辑。

My current code is: 我当前的代码是:

    playerLists["MIN - Minnesotta Vikings"].push(["Player 1"]);         
    playerLists["ARI - Arizona Cardinals"].push(["Player 1"]);          
    playerLists["DAL - Dallas Cowboys"].push(["QB Tony Romo "]);    
    playerLists["DAL - Dallas Cowboys"].push(["RB Tyler Clutts"]); 
    playerLists["DAL - Dallas Cowboys"].push(["WR Cole Beasley"]); 

...etc.... ...等等....

Thanks for any help you can give. 谢谢你提供的所有帮助。

Why you just do not push the image url and use it like this : 为什么不直接推送图像网址并像这样使用它:

playerLists["MIN - Minnesotta Vikings"].push({ name: "Player 1", url: "/path_to_image.png" });         
playerLists["ARI - Arizona Cardinals"].push({ name: "Player 2", url: "/path_to_image.png" });         
playerLists["DAL - Dallas Cowboys"].push({ name: "Player 3", url: "/path_to_image.png" });         
playerLists["DAL - Dallas Cowboys"].push({ name: "Player 4", url: "/path_to_image.png" }); 

After that, when you make an iteration you can do : 之后,当您进行迭代时,您可以执行以下操作:

_.each(playerLists, function(player){
  console.log(player.name);
  console.log(player.url);
})

(To use _.each, you have to install http://underscorejs.org/ ) (要使用_.each,必须安装http://underscorejs.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM