我正在使用精选控件来级联从联赛,球队到球员的过滤器选择。我试图将播放器配置文件图像添加到每个播放器,但我似乎无法在Array.push中添加img。有关如何使用选择控件在播放器名称旁边渲染图像的任何想法?我有许多值的级联过滤器设置,所以我试图不必为级联选择控件及其数组值创建新逻辑。
我目前的代码是:
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"]);
...等...
感谢您提供任何帮助。
答案 0 :(得分:1)
为什么你不按下图像网址并像这样使用它:
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" });
之后,当你进行迭代时,你可以这样做:
_.each(playerLists, function(player){
console.log(player.name);
console.log(player.url);
})
(要使用_.each,您必须安装http://underscorejs.org/)