[英]Using a custom jQuery function in an ASP.NET MVC application
I found this jQuery plugin which makes dropdownlists searchable ( http://jsearchdropdown.sourceforge.net/ ). 我找到了这个jQuery插件,它使下拉列表可搜索( http://jsearchdropdown.sourceforge.net/ )。 It's something I'd really like to use in my project, but I am experiencing a few problems.
我真的很想在项目中使用它,但是我遇到了一些问题。 This is how I make the DropDownList, I also give it an id so I can apply the function to the dropdownlist:
这是我制作DropDownList的方法,我也给它提供了一个ID,以便可以将该函数应用于dropdownlist:
<div id="geadresseerde-politici">
@Html.Label("Politicus")
@Html.DropDownListFor(model => model.PoliticianId, (SelectList)ViewBag.PolIds, new{@id = "polDrop"})
</div>
I also include the .min.js file in my <head>
section like so: 我还在
<head>
部分中包含.min.js文件,如下所示:
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.searchabledropdown-1.0.8.min.js")"></script>
And my javascript part: 而我的JavaScript部分:
$(document).ready(function() {
$("#polDrop").searchable();
});
When I try to use my page the dropdownlist is not searchable and I get an error in the Chrome console saying: Uncaught TypeError: Object [object Object] has no method 'searchable'
当我尝试使用我的页面时,无法搜索下拉列表,并且在Chrome控制台中收到错误消息:
Uncaught TypeError: Object [object Object] has no method 'searchable'
Does anyone have any idea what I could be doing wrong. 有谁知道我可能做错了什么。 Do I need to include more files?
我需要包括更多文件吗? I checked in the sources tab of Chrome (in the ctr+shift+i helper) and the .min.js script gets loaded.
我检查了Chrome的“源”标签(在ctr + shift + i帮助器中),并加载了.min.js脚本。 Do I need to 'tellt my code somehow that the searchable() function is in that extra js file and not in the standard js library?
我是否需要以某种方式告诉我的代码searchable()函数在该额外的js文件中,而不在标准js库中?
The Way You Were Trying = 1 way
Second Way
Asp.net
Push Array In Asp.net ViewData['MYDATALIST'] As serialized data.
Jquery/js
my list = $('MYDATALIST').val();
Now Push This Array List In Your Select.
Also add these files.Seems like they are also needed.Also change the location as yours 还要添加这些文件。似乎也需要它们。还要更改位置为您的位置
<link type="text/css" rel="stylesheet" href="sh/shCore.css"/>
<link type="text/css" rel="stylesheet" href="sh/shThemeDefault.css"/>
<script type="text/javascript" src="sh/shCore.js"></script>
<script type="text/javascript" src="sh/shBrushJScript.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.