简体   繁体   English

在ASP.NET MVC应用程序中使用自定义jQuery函数

[英]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.

相关问题 在ASP.NET MVC 3应用程序中替换jQuery - Replacing jQuery in ASP.NET MVC 3 application 使用ASP.NET MVC 3 **没有** jQuery - Using ASP.NET MVC 3 **WITHOUT** jQuery 在ASP.NET MVC 5应用程序中有效的表单时触发jQuery函数 - Trigger jQuery function when form valid in ASP.NET MVC 5 application 在ASP.NET MVC应用程序中的Jquery中的悬停方法 - Hover method in Jquery within asp.net mvc application ASP.NET MVC 3剃刀视图中的jQuery自定义验证 - jQuery custom validation in asp.net mvc 3 razor view 使用Javascript / jQuery AJAX的ASP.NET MVC 3单页面应用程序:内存和分离的DOM问题 - ASP.NET MVC 3 Single-Page Application using Javascript/jQuery AJAX: Memory and Detached DOM Issues 在 ASP.net MVC 5 应用程序中单击按钮时使用 JavaScript/jQuery 将用户重定向到页面 - Redirect user to a page using JavaScript/jQuery on button click in ASP.net MVC 5 application 如何在ASP.NET MVC3中使用jQuery函数将值从视图传递到控制器 - How to pass values from view to controller using jquery function in asp.net mvc3 Jquery 键控 function 不起作用(使用 ajax、Z1848E732214CCE460E7Zvc8F4C) - Jquery keyup function doesn't work (using ajax, asp.net mvc) jQuery自动完成-TypeError:自动完成不是ASP.NET MVC 5中的函数 - jQuery autocomplete - TypeError: autocomplete is not a function in asp.net mvc 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM