开发者

Load objects in array and return array like result

I create in Dojo class element and classes in, out and motor which are derived from el开发者_C百科ement. I load elements from JSON file and with dojo.foreach I create instance of given type. Is there in Dojo array for this ? How to add this to array ? ( I'm comming from Java and this is strange to me not to have types like List )?


Your question is rather unclear, but in JavaScript, arrays work like Java's arrays and arraylists.

var arr1 = [0, 1, 2, 3]; // array literal construction
var arr2 = [];

for (var i=0; i<4; i++)
{
    arr2.push(i); // add new values to the array, like Java's Array#add()
}
// now arr2 contains the same values as arr1

For more info, see MDC's Array docs.


In javascript you've got arrays just like you do in Java, although their behaviour is quite different(see the link for more information). You can instantiate an array like this:

var data = [];

Or:

var data = [ 1, "hello", 23, 23.45 ];

As you can see arrays in javascript can contain mixed values.

Hope this helped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜