将数组(或TList)从C#代码传递到外部javascript? [英] Pass array (or TList) from C# code behind to external javascript?

查看:131
本文介绍了将数组(或TList)从C#代码传递到外部javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将IP地址列表(或数组)和来自C#代码的其他信息传递给外部js中的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..

此外,此列表可能很长(超过1000个项目)..最有效的方法是什么?你能提供一个小例子吗?我应该使用json序列化吗?

Also, this list may be long (1000+ items) .. What is the most efficient way to do this? can you provide a small example? should I use json serialization?

推荐答案

var myObject = <%= JustSerializeAsJson(...) %>; ...或将其传递给函数.重点是JSON是有效的JavaScript文字,因此您可以将其放在很多地方.除非存在配置文件问题,否则请不要担心此处的效率".生成和JavaScript解析都应该真正快. (必应地图在JS中加载了1MB的文件!)

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. Don't worry about "efficiency" here unless there is a profiled problem. Both the generation and JavaScript parsing should be really fast. (Bing maps loads like 1MB file in JS!)

MSDN JSON序列化器

这篇关于将数组(或TList)从C#代码传递到外部javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆