对 XMLList 进行切片而不是数组
如何从 xmllist 中获取一系列项目,类似于数组的切片方法?
切片(起始索引,结束索引);
我正在尝试这样的事情:
var tempXMLList:XMLList = new XMLList();
for( var i:int = startIndex; i <= endIndex; i++){
tempXMLList += originalList[i];
}
但我收到一个错误,它无法转换originalList[i]
--- 更新 ---
我使用了 Timofei 的函数,它工作得很好。
private function SliceXMLList(xmllist : XMLList, startIndex : int, endIndex : int) : XMLList
{
return xmllist.(childIndex() >= startIndex && childIndex() <= endIndex);
}
但是,当我使用已过滤的 xmllist 时,它会崩溃。
filteredData = filteredData.(team == "Ari");
trace("filteredData.length(): " + filteredData.length().toString());
pData = SliceXMLList(filteredData, startIndex, endIndex);
trace("start: " + startIndex.toString() + " end: " + endIndex.toString());
trace("pdata length: " + pData.length().toString());
输出
filteredData.length(): 55
start: 0 end: 55
pdata length: 5
How would I get a range of items from my xmllist similar to the slice method for an array?
slice(startIndex,endIndex);
I am trying something like this:
var tempXMLList:XMLList = new XMLList();
for( var i:int = startIndex; i <= endIndex; i++){
tempXMLList += originalList[i];
}
But I am getting an error that it can't convert originalList[i]
--- Update ---
I used Timofei's function and it worked perfectly.
private function SliceXMLList(xmllist : XMLList, startIndex : int, endIndex : int) : XMLList
{
return xmllist.(childIndex() >= startIndex && childIndex() <= endIndex);
}
However, when I use an xmllist that was already been filtered, it breaks.
filteredData = filteredData.(team == "Ari");
trace("filteredData.length(): " + filteredData.length().toString());
pData = SliceXMLList(filteredData, startIndex, endIndex);
trace("start: " + startIndex.toString() + " end: " + endIndex.toString());
trace("pdata length: " + pData.length().toString());
output
filteredData.length(): 55
start: 0 end: 55
pdata length: 5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 e4x。
更新:
如果您打算在进行一些 e4x 排序后使用此函数,则会出现问题,因为 childIndex() 函数返回节点索引的旧值并且无法更改。所以,我有另一个想法:
或者只是
我认为这是最好的变体。当然,一行 e4x 语句要优雅得多,但不幸的是它不可重用。
Use e4x.
Update:
There's a problem, if you're going to use this function after some e4x-sorting, 'cause the childIndex() function returns the old values of the nodes' indexes and it cannot be changed. So, I have another idea:
or just
This is the best variant, i think. Of course one-line e4x statement is much more elegant, but unfortunately it's not reusable.
不确定您期望它如何工作,但是您可以迭代所有子项,并将每个子项保存到一个数组中,然后以这种方式修剪它们
not sure how you expect it to work, but you could iterate through all children, and save each one into an array, and then trim them that way