如何将objective C中的数组显示到HTML或JavaScript中,在HTML中显示数组的内容
How to display the array which is in objective C to the HTML or JavaScript,to display the contents of array on a buttonclick in HTML
如何在HTML或JavaScript中显示objective C中的数组,如何在HTML中显示数组的内容,
下面的代码是我的。m文件代码,[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Array"ofType:@"html"]isDirectory:NO]]];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Example" ofType:@"csv"];
NSString *contents = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding error:nil];
NSArray *lines = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"'n,"]];
for (NSString* line in lines) {
NSLog(@"%@", line);
}
NSLog(@" %d", [lines count]);
[self.webView performSelectorOnMainThread:@selector(stringByEvaluatingJavaScriptFromString:) withObject:[NSString stringWithFormat:@"checkContents = new Array%@",lines] waitUntilDone:NO];
下面是我的HTML文件代码
function checkContents(Lines) {
// alert("test...");
alert(checkContents[0]);
// alert(document.lines[0]);
if (typeof(checkContents)=='undefined')
....
else {
if (checkContents.length == 0)
....
else {
for (i=0; i<checkContents.length; i++) {
}
}
}
}
<body onload="checkContents()">
<div class="greybutton" onClick="javascript:checkContents()">contents</a></div>
</body>
当我运行这个程序时,它显示未定义作为警报中的输出,我是否在HTML文件中缺少任何代码或我正在做错误的地方。
可以使用CFArrayRef
http://developer.apple.com/library/mac/文档/CoreFoundation/引用/CFArrayRef/引用/必要reference.html
是一个C类其中NSArray是obj-c版本。你可以动态地改变类型,所以你可以改变它并使用c类型字符串发送给javascript。
相关文章:
- 使用jQuery在html数组中设置一个值
- HTML 数组乘以 javascript
- 如何在javascript中处理html数组元素,并使用ajax将它们传递给控制器
- 无法将html数组传递给JS
- 使用 jQuery 更改基于下拉 html 数组的文本框
- 如何动态添加HTML数组元素[]
- 如何从HTML数组中获取文本区域的值
- PHP中的HTML数组字段解析
- Javascript html 数组未保存和显示
- HTML数组脚本不工作(in_Array未定义)
- 从动态HTML数组创建对象
- 根据输出对HTML数组进行排序
- 在js php/html数组中保存/检索复选框
- 通过PHP迭代HTML数组
- 使用Javascript获取HTML数组长度
- 使用html数组按名称获取元素
- 从HTML "数组"javascript数组
- 我可以在JavaScript中选择一个多维HTML数组作为多维数组吗
- 如何使用jQuery将值插入到html数组中
- 如何通过AJAX发送HTML数组