我正在尝试为一个表创建一个数组数组(在onSelect函数中使用来自dynaTree的标题)。我可以成功地从节点中检索dynatree标题,但是无论我做什么,我似乎都不能从这些值中生成一个数组。
只有字符串数组titles...bascially的返回行忽略了数组的括号和拼接?
onSelect: function(flag, node)
{
var selectedNodes = node.tree.getSelectedNodes();
var selectedKeys = $.map(selectedNodes, function(node)
{
return node.data.id;
});
var selectedTitles = $.map(selectedNodes, function(node)
{
var name = node.data.title;
name = name.substring(0,4);
if(name == 'Room')
{
var floor = node.getParent();
var building = floor.getParent();
//PROBLEM CODE(not creating arrays):
return([node.data.title,floor.data.title,building.data.title] );
}
});
console.log("Selected Titles: " + selectedTitles);
},当前结果:
Selected Titles: Room 115,Floor 1,Chemistry, Room 116,Floor 01,Chemistry,
Room 114,Floor 01,Chemistry, Room 113,Floor 01,Chemistry, Room 112,Floor
01,Chemistry, Room 110,Floor 01,Chemistry, Room 109,Floor 01,Chemistry, Room
109A,Floor 01,Chemistry预期结果:
Selected Titles: [Room 115,Floor 1,Chemistry],[Room 116,Floor 01,Chemistry],
[Room 114,Floor 01,Chemistry],[Room 113,Floor 01,Chemistry],[Room 112,Floor
01,Chemistry],[Room 110,Floor 01,Chemistry],[Room 109,Floor 01,Chemistry],
[Room 109A,Floor 01,Chemistry]发布于 2015-07-30 16:55:13
我找到解决方案了!!我在前面的注释中做了所有的事情,没有看到任何change...then尝试在返回语句周围添加另一个数组容器。
感谢charlietfl & John Green推荐控制台日志并删除字符串,而没有更改这种草率的代码,该结构将不会作为数组的数组可见。
return( [[node.data.title,floor.data.title,building.data.title]]); 我不知道为什么map方法需要一个包含数组?但是工作起来就像预期的那样!
https://stackoverflow.com/questions/31699786
复制相似问题