简体   繁体   English

将数组(或TList)从C#代码传递到外部JavaScript?

[英]Pass array (or TList) from C# code behind to external javascript?

I need to pass a list (or array) of IP addresses and other information from C# code behind to the javascript function, which is in the external .js.. 我需要将IP地址和其他信息的列表(或数组)从C#代码传递到外部js中的javascript函数。

Also, this list may be long (1000+ items) .. What is the most efficient way to do this? 另外,此列表可能很长(超过1000个项目)..最有效的方法是什么? can you provide a small example? 你能提供一个小例子吗? should I use json serialization? 我应该使用json序列化吗?

var myObject = <%= JustSerializeAsJson(...) %>; ... or pass it to a function to whatever. ...或将其传递给函数。 Point is JSON is a valid JavaScript literal so you can drop it in a number of places. 重点是JSON是有效的JavaScript文字,因此您可以将其放在很多地方。 Don't worry about "efficiency" here unless there is a profiled problem. 不要担心“效率”在这里,除非有一个异形的问题。 Both the generation and JavaScript parsing should be really fast . 生成和JavaScript解析都应该非常快 (Bing maps loads like 1MB file in JS!) (Bing映射在JS中加载1MB文件!)

MSDN JSON Serializer MSDN JSON序列化器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM