Now I want to transform a Array from object_c to javascript, just like label1 , label2 , label3... in the array. I use this method :
WebScriptObject* win = [webview windowScriptObject];
NSMutableArray *nameArray; // in this have some file name : label1,label2...
[win callWebScriptMethod:@"transArray" withArguments:nameArray];
and then in the javascript I var a array and implement a func:
var labelArray= []; // maybe var labelArray = new Array (%@);but it didn't work
function transArray(param)
{
for(var i=0;i < param.length;i++)
labelArray[i] = param[i];
}
then I found that the labelArray isn't like I want. it just like : labelArray[0] = l,labelArray[1] = a; labelArray[2] = b
..... .I thought maybe I could var labelArray = new Array (%@)
.but it didn't work. I don't know the javascript clearly , and if I can transform a array from object_c to javascript or not , how to do ? thanks!
Now I found the method that transformming the argu from object_c to Javascript. But I didn't know how to get the array in the javascript , I thought maybe my method was wrong , but how to get the array and var the array,Thanks !
id win = [webView windowScriptObject];
NSArray *args = [NSArray arrayWithObjects:
@"sample_graphic.jpg",
[NSNumber numberWithInt:320],
[NSNumber numberWithInt:240],
nil];
[win callWebScriptMethod:@"addImage"
withArguments:args];
from WebKit Objective-C Programming Guide
withArguments:
argument is for. It uses the contents of the array as the arguments to the JavaScript function named (in this example) addImage
- Peter Hosey 2009-09-30 07:04
You could take a peek at JSON encoding/decoding. This is by far the easiest way I know of to get data from and to javascript.
http://www.json.org/ has a list of available classes at the bottom of the homepage. I'm pretty sure there is one that will suit your needs.
Hope this helps!
ok I found the answer: function addImage() { for(var i=0;i
You should code like this:
[win callWebScriptMethod:@"transArray" withArguments:@[nameArray]];