Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从list.js中的{id:3,name:";John";}获取值_Javascript_Html_Object_Listjs - Fatal编程技术网

Javascript 从list.js中的{id:3,name:";John";}获取值

Javascript 从list.js中的{id:3,name:";John";}获取值,javascript,html,object,listjs,Javascript,Html,Object,Listjs,我用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) {

我用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,名称:“Marc”…}

itemValues.name->Marc

Udate

忘记使用uid函数(“id”)。当我使用values()时,它会起作用。谢谢你的回答

更新小提琴

您可以使用阵列筛选方法(IE9+):


您可以使用阵列筛选方法(IE9+):


您的id字段称为uid,要获取对象的值,需要调用结果中的.values,因此:

function getUserName(uid) {
    var itemValues = hackerList.get("uid", uid)[0].values();
    console.log("The name of the user is: " + itemValues.name);
}

您的id字段称为uid,要获取对象的值,需要调用结果中的.values,因此:

function getUserName(uid) {
    var itemValues = hackerList.get("uid", uid)[0].values();
    console.log("The name of the user is: " + itemValues.name);
}

您需要帮助的问题是什么?您需要帮助的问题是什么?我试过了,但它不是jquery的函数吗?I get:Uncaught TypeError:无法调用Undefine的方法“values”您是否已将hackerList.get(“id”,uid)更改为hackerList.get(“uid”,uid)?在您的fiddle示例中,您将id字段命名为“uid”,我试过了,但它不是jquery中的一个函数吗?I get:Uncaught TypeError:无法调用Undefine的方法“values”您是否已将hackerList.get(“id”,uid)更改为hackerList.get(“uid”,uid)?在fiddle示例中,您将id字段命名为“uid”,这是一种方式。但它会再次搜索列表,我想使用listjs,这对所有浏览器都更好。谢谢。我误解了你的问题,以为你不想因为某种原因而列出。js…这是一种方式。但它会再次搜索列表,我想使用listjs,这对所有浏览器都更好。谢谢。我误解了你的问题,以为你不想出于某种原因列出.js。。。