0
在我的代碼中,字段長度始終爲0,並且我非常肯定它中有一些鍵 - 值對。循環散列
var fields = Reflect.fields(_commandMap);
trace("mapping "+fields.length);
在我的代碼中,字段長度始終爲0,並且我非常肯定它中有一些鍵 - 值對。循環散列
var fields = Reflect.fields(_commandMap);
trace("mapping "+fields.length);
您無法在哈希中以數組形式訪問值。
這裏是一個Hash
var a = new Hash();
a.set("hello", 0);
a.set("bonjour", 1);
a.set("ohai", 2);
下面是一些方法,您可以訪問值/鍵:
for (value in a)
{
trace(value); //Will trace 0, 1, 2 (no assurance that it will be in that order)
}
for (key in a.keys())
{
trace(key); //Will trace hello, bonjour, ohai (no assurance that it will be in that order)
}
如果你想你的哈希轉換爲數組,使用Lambda:
var valueArray = Lambda.array(a);
trace(valueArray[0]); //can be 0, 1 or 2
//since keys() returns an Iterator, not an Iterable, we cannot use Lambda here...
var keyArray = [];
for (key in a.keys()) keyArray.push(key);
trace(keyArray[0]); //can be hello, bonjour or ohai
你的問題到底是什麼? – Nanomurf
你能詳細說明嗎?您用來填充Reflect對象的方法將很有用。 –
沒有更多的上下文,很難說出發生了什麼。從文檔說,Reflect.fields只能保證在匿名對象上工作,否則使用Type.getClassFields()。也許試試? (http://haxe.org/api/reflect)否則,張貼更多的上下文:) –