Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Problem with arrays in javascript (v8)

0
0
Hello, and thanks for your question!

It looks like you're asking about host (.NET) arrays rather than JavaScript arrays. Is that correct?

ClearScript's general approach is to avoid data conversion and provide full access to .NET objects. There are exceptions, mainly numbers and strings, but host arrays are exposed "as is"; that is, they are not converted to script arrays.

Normally ClearScript exposes the members of a host object (fields, properties, and methods) as properties of the corresponding JavaScript "proxy" object. Additionally, if a host object implements IList, as arrays do, ClearScript also exposes its valid indices, enabling JavaScript's familiar foo[123] syntax for element access.

So yes, if you use JavaScript's for...in statement to iterate over a host array, you'll get both its elements and its members, and it does appear that Handlebars's each helper works this way.

Consider applying the each helper not directly to a host array but to the output of a conversion function:
function convertArray(hostArray) {
    var result = [];
    for (var i = 0; i < hostArray.Length; i++)
        result.push(hostArray[i]);
    return result;
}
Another possibility might be to override the built-in helper with one that supports host arrays.

Cheers!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images