mvc JQuery JSON.parse() 填充下拉列表
我想填充从 JSON.parse() 返回的 Javascript 对象的下拉列表。尝试过但没有成功。请帮忙
<script type="text/javascript" charset="utf-8">
<br />
//This is returned from Model. All I want to put that in dropdown.<br />
//var cat = JSON.parse('[{"Selected":false,"Text":"Blue","Value":"1"},{"Selected":false,"Text":"Red","Value":"2"},{"Selected":false,"Text":"Grey","Value":"3"},{"Selected":false,"Text":"Black","Value":"4"},{"Selected":false,"Text":"Green","Value":"5"},{"Selected":false,"Text":"Olive","Value":"6"},{"Selected":false,"Text":"Orange","Value":"7"},{"Selected":false,"Text":"Pink","Value":"8"},{"Selected":false,"Text":"Violet","Value":"9"},{"Selected":false,"Text":"Yellow","Value":"10"}]');
<br /><br />
var cat = JSON.parse('<%= Html.ToJson(Model.Colors) %>');
<br />
</script>
I want to fill dropdown from the Javascript object returned from JSON.parse(). Tried but not successfull. Please help
<script type="text/javascript" charset="utf-8">
<br />
//This is returned from Model. All I want to put that in dropdown.<br />
//var cat = JSON.parse('[{"Selected":false,"Text":"Blue","Value":"1"},{"Selected":false,"Text":"Red","Value":"2"},{"Selected":false,"Text":"Grey","Value":"3"},{"Selected":false,"Text":"Black","Value":"4"},{"Selected":false,"Text":"Green","Value":"5"},{"Selected":false,"Text":"Olive","Value":"6"},{"Selected":false,"Text":"Orange","Value":"7"},{"Selected":false,"Text":"Pink","Value":"8"},{"Selected":false,"Text":"Violet","Value":"9"},{"Selected":false,"Text":"Yellow","Value":"10"}]');
<br /><br />
var cat = JSON.parse('<%= Html.ToJson(Model.Colors) %>');
<br />
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下代码来完成此操作,
HTML 是,
JQuery 代码是,
它将在单击按钮时填充下拉列表。
You can do this by using following code,
HTML is,
JQuery Code is,
It will Fill Dropdownlist on Button Click.