我用 listjs (listjs.com) 列了一个列表
现在我正在使用函数 get(),这会给我这个回报:
itemsInList = [
{ id: 1, name: "Jonny" }
, { id: 2, name "Gustaf" }
];
listObj.get("id", 2); -> return { id: 2, name: "Gustaf" }
现在我只想用纯 javascript 获取名称 id。
function getUserName(uid) {
var itemValues = hackerList.get("id", uid)[0];
console.log("The name of the user is: " + itemValues.name);
// or use alert..
//alert("The name of the user is: " + itemValues.name);
}
抱歉不具体......我想从返回值:
{ uid:2,名称:“马克” ... }
到itemValues.name -> Marc
乌馆
忘记使用 uid 函数(“id”)。当我使用 values() 时,它会起作用。谢谢你的回答。
更新的小提琴 小提琴