2017-08-16 27 views
1

转发此信息是因为我找不到任何不涉及使用Google捆绑包或其他内容的答案。请告诉我,如果我错过了任何细节,我会添加它。我有包含我的_layout顶部引用VS全jQuery的包......('...')。每个都不是一个有效的用于jquery包的mvc核心功能

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

这里的BundleConfig.cs

public static void RegisterBundles(BundleCollection bundles) 
     { 
      bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
         "~/Scripts/jquery-{version}.js")); 

      bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
         "~/Scripts/jquery.validate*")); 

      // Use the development version of Modernizr to develop with and learn from. Then, when you're 
      // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. 
      bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
         "~/Scripts/modernizr-*")); 

      bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
         "~/Scripts/bootstrap.js", 
         "~/Scripts/respond.js")); 

      bundles.Add(new StyleBundle("~/Content/css").Include(
         "~/Content/bootstrap.css", 
         "~/Content/site.css")); 
     } 

...但它仍然告诉我,在这种情况下,那.each不是一个函数。我缺少什么或需要参考布局或BundleConfig?为什么不是.each这个函数是Visual Studio 2017附带的jQuery包的一部分?

@Html.ListBox("Groups", null, new { size = 10, style = "width : 350px; max-width : 500px;", id = "grouplist" }) 

我的jQuery的整个来龙去脉:

$('#savegroups').click(function() { 
      var groupId = $('#groupId').val(); 
      var list = []; 
      ('#grouplist').each(function (item) { 
       list.append('{"groupId":"' + groupId + '","groupName":"' + item.value +'"}'); 
      }); 
      $.ajax({ 
       type: "POST", 
       url: "/GroupCategories/EditGroups", 
       data: JSON.stringify(list), 
      }); 
    }); 

错误:

1:230 Uncaught TypeError: "#grouplist".each is not a function 
    at HTMLInputElement.<anonymous> (1:230) 
    at HTMLInputElement.dispatch (jquery:1) 
    at HTMLInputElement.y.handle (jquery:1) 
+1

更改**('#grouplist')**到** $('#grouplist')** – gaetanoM

+0

我试过了,它只是跳过了整个循环。 –

回答

4

看起来你缺少jQuery选择..

('#grouplist') 

应该

$('#grouplist option') 
+0

如何在添加美元符号选择器后完全跳过循环? –

+2

更新我的答案,添加'选项'循环通过项目 – mcbowes

+0

我认为它工作,但它不是,即使添加选项它仍然忽略循环,它会去每一行,然后跳过循环,尽管项目在列表框。我会发布一个单独的问题,因为这是我认为的另一个问题。 –

相关问题