Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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字典键和值传递到函数中?_Javascript_Jquery_Dictionary - Fatal编程技术网

如何将此Javascript字典键和值传递到函数中?

如何将此Javascript字典键和值传递到函数中?,javascript,jquery,dictionary,Javascript,Jquery,Dictionary,这个名为dict的字典将表Id选择器作为键,“Hellos”作为值 如何将此字典传递到名为applyDictionary的函数中,该函数从字典中获取tableId键和值“Hellos” 此函数不接受jQuery选择器ID作为参数,因为我不能用#传递字典表键 例如,我无法通过applyDictionary(#tbl,'hello') 仅限applyDictionary(tbl,“hello”) var dict={ #tbl:"你好",, “#tbl1”:“你好”, “#tbl2”:“你好”, #

这个名为dict的字典将表Id选择器作为键,“Hellos”作为值

如何将此字典传递到名为applyDictionary的函数中,该函数从字典中获取tableId键和值“Hellos”

此函数不接受jQuery选择器ID作为参数,因为我不能用#传递字典表键

例如,我无法通过applyDictionary(#tbl,'hello')

仅限applyDictionary(tbl,“hello”)

var dict={
#tbl:"你好",,
“#tbl1”:“你好”,
“#tbl2”:“你好”,
#tbl3':“你好”,
};
applyDictionary(表ID,值);

首先获取对象的条目,对于每个条目,应用带有id和值的函数,然后去掉id的第一个字符

Object.entries(dict).map(([id, value]) => applyDictionary(id.slice(1), value))
解释:

Object.entries(dict) // Get entries of the object as 2-items arrays with the key and the value
  .map(([id, value]) => // destructure every item
    applyDictionary(
      id.slice(1), // Get rid of the first character and pass it as first argument to applyDictonary
      value, // Pass the value as 2nd argument
    )
  )

您可以使用
Object.entries()

例如:

var tblnsnsearchresults_tooltips  = {
    '#tblnsnsearchresults_uoicd': 'hello',
    '#tblnsnsearchresults_nsnid': 'hello1',
    '#tblnsnsearchresults_fsccd': 'hello2',
    '#tblnsnsearchresults_nsndescription': 'hello3',
};

let applycolumnheadertooltips = entries =>
    entries.forEach(([gridId, tooltips])=>console.log(`${gridId} => ${tooltips}`));

    applycolumnheadertooltips(Object.entries(tblnsnsearchresults_tooltips ));

很难理解你想要完成什么;
applyDictionary
的预期输出是什么?您可以尝试applyDictionary('tbl','hello');谢谢你的帮助!!不客气!