不支持JQuery用户界面排序()方法错误 [英] JQuery UI sortable() method not supported error

查看:134
本文介绍了不支持JQuery用户界面排序()方法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个ASP.NET MVC 4 Web应用程序,它采用了最新的JQuery和JQuery UI库,并自动拥有对它们的引用(在_Layout.cshtml页)。

I'm developing an ASP.NET MVC 4 web application, which utilises the latest JQuery and JQuery UI libraries, and automatically has references to them (in the _Layout.cshtml page).

我一直在关注本教程这里实现拖放在表上重新排序功能。

I've been following the tutorial here to implement drag and drop reordering functionality on a table.

但是,即使我明确地添加引用的视图模型,其中它所需的最新JQuery用户界面的文件,例如

But even when I explicitly add the reference to the latest JQuery UI file on the view model where it's required, e.g.

<script src="/Scripts/jquery-ui-1.10.2.min.js" type="text/javascript"></script>

的排序()方法不起作用。它不会在Visual Studio智能感知显示出来,并运行时,它不起作用。对在Internet Explorer(或任何浏览器)运行的,我只是得到一个错误,指出对象不支持属性或方法'排序'

下面是我正在试图使用的方法:

Here is how I'm attempting to use the method:

        <script type="text/javascript">
        $(document).ready(function()
        {
            $("#clueTable tbody").sortable();
        });
        </script>

我注意到从智能感知有一个属性sortables'和'排序',它从jQuery UI文件找到,但不是'排序'。

I notice from the Intellisense there is a property 'sortables' and 'sort' that it finds from the JQuery UI file, but not 'sortable'.

所以引用显得精致,而且绝对是最新的JQuery UI code(我通过获取最新的文件证实这一点),所以我有点迷惑与这一个。

So the reference seems fine, and it's definitely the latest JQuery UI code (I verified this by getting the latest file) so I'm a bit mystified with this one.

推荐答案

在_Layout.cshtml,它看起来像在某些时候我手动引用的jQuery和JQuery用户界面脚本,忘记了脚本是成捆已经呈现,例如

In the _Layout.cshtml, it looks like at some point I manually referenced the JQuery and JQuery UI scripts, forgetting that the scripts were already rendered in bundles, e.g.

@Scripts.Render("~/bundles/jquery")

我是正确引用正确的脚本,而是因为他们被再次装入,我认为他们正在摧毁这个文件的第一个实例,包括JQuery用户界面code,它依赖于被加载JQuery的文件。

I was correctly referencing the right scripts but because they were being loaded again, I think they were destroying the first instances of the files, including the JQuery UI code, which relies on the JQuery file being loaded.

我不也明白的是,在默认情况下,ASP.NET MVC 4应用程序不会使JQuery的UI框架,尽管该项目存在的文件,并在文件BundleConfig.cs创建一个脚本包。

What I didn't understand also was that by default, ASP.NET MVC 4 applications do not render the JQuery UI framework, even though the files exist in the project and a script bundle is created in the BundleConfig.cs file.

因此​​,要解决自己的问题,我删除了所有的手动引用,以便只有包被渲染,并添加以下行来呈现在我的_Layout.cshtml文件的头部JQuery用户界面code:

Therefore, to fix my problems, I removed all the manual references so that only the bundles were being rendered, and added the following line to render the JQuery UI code in the head of my _Layout.cshtml file:

@Scripts.Render("~/bundles/jqueryui"); 

束出现的工作方式是,Global.asax文件调用'RegisterBundles的BundleConfig.cs,它通过在脚本文件夹和任何其他地方寻找相关的JavaScript文件创建新的脚本捆绑的方法你告诉它的样子。

The way the bundles appear to work is that the Global.asax file invokes the 'RegisterBundles' method of the BundleConfig.cs, which creates new script bundles by searching for the relevant JavaScript files in the 'Scripts' folder and wherever else you tell it to look.

然后,装入从HTML脚本文件,你必须使用@ Script.Render(),并提供脚本包的名称作为参数(例如〜/包/ jQueryUI的),使它们。

Then, to load the script files from the HTML, you have to render them using @Script.Render(), and providing the name of the script bundle as a parameter (e.g. "~/bundles/jqueryui").

要渲染网站的每个页面上的所有脚本,可以将其添加到_Layout.cshtml文件,该文件被应用到每一页。

To render all the scripts on every page of the website, you can add this to the _Layout.cshtml file, which is applied to every page.

这篇关于不支持JQuery用户界面排序()方法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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