emacs和python更新模块(emacs and python updating modules)
atm我正在使用emacs编写一些python代码,到目前为止它工作得很好,除了一个真的有点烦人的问题。
总是当我在自编写模块中更新内容时,我重新评估缓冲区并且emacs内部的python shell中的模块不会更新。 我总是必须结束python进程并再次启动它以获得更改。 我发现emacs将一些东西复制到tmp目录来执行它们,所以我猜它与此有关。
也许有人在那里有同样的问题,并已解决它,所以帮助将不胜感激
atm i'm using emacs to write some python code, so far it works quite fine except one problem that is really a bit annoying.
Always when I update something inside a self written module i reevaluate the buffer and the module in the python shell inside emacs doesn't get updated. i always have to end the python process and start it again to get the change. I figured out that emacs copies some things to a tmp dir to execute them, so i guess it has something to do with this.
Maybe someone out there had the same problem and solved it already so help would be appreciated
原文:https://stackoverflow.com/questions/6942627
最满意答案
这是一个完整的例子。
模型:
public class MyViewModel { public int Year { get; set; } public IEnumerable<SelectListItem> Years { get { return Enumerable.Range(1980, 40).Select(x => new SelectListItem { Value = x.ToString(), Text = x.ToString() }); } } public IList<TheData> Data { get; set; } } public class TheData { public int Year { get; set; } public string Foo { get; set; } public string Bar { get; set; } }
控制器:
public class HomeController : Controller { public ActionResult Index() { var model = new MyViewModel(); return View(model); } [HttpPost] public ActionResult Index(int year) { var model = new[] { new TheData { Year = year, Foo = "foo 1", Bar = "bar 1" }, new TheData { Year = year, Foo = "foo 2", Bar = "bar 2" }, new TheData { Year = year, Foo = "foo 3", Bar = "bar 3" }, }; return PartialView("_data", model); } }
Index.cshtml
查看:@model MyViewModel <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('#yearsddl').change(function () { $(this).closest('form').trigger('submit'); }); }); </script> @using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "data" })) { @Html.DropDownListFor(x => x.Year, Model.Years, new { id = "yearsddl" }) } <table> <thead> <tr> <th>Year</th> <th>Foo</th> <th>Bar</th> </tr> </thead> <tbody id="data"> @Html.Partial("_data", Model.Data ?? Enumerable.Empty<TheData>()) </tbody> </table>
例如,
jquery.unobtrusive-ajax.js
脚本包含移出布局中的索引视图,并且订阅下拉列表更改事件的自定义js应移至单独的js文件中,并从布局中包含。 我只是把它们放在这里来说明视图工作所需的完整示例。
_Data.cshtml
部分:@model IList<TheData> @for (int i = 0; i < Model.Count; i++) { <tr> <td>@Html.DisplayFor(x => x[i].Year)</td> <td>@Html.DisplayFor(x => x[i].Foo)</td> <td>@Html.DisplayFor(x => x[i].Bar)</td> </tr> }
Here's a full example.
Model:
public class MyViewModel { public int Year { get; set; } public IEnumerable<SelectListItem> Years { get { return Enumerable.Range(1980, 40).Select(x => new SelectListItem { Value = x.ToString(), Text = x.ToString() }); } } public IList<TheData> Data { get; set; } } public class TheData { public int Year { get; set; } public string Foo { get; set; } public string Bar { get; set; } }
Controller:
public class HomeController : Controller { public ActionResult Index() { var model = new MyViewModel(); return View(model); } [HttpPost] public ActionResult Index(int year) { var model = new[] { new TheData { Year = year, Foo = "foo 1", Bar = "bar 1" }, new TheData { Year = year, Foo = "foo 2", Bar = "bar 2" }, new TheData { Year = year, Foo = "foo 3", Bar = "bar 3" }, }; return PartialView("_data", model); } }
Index.cshtml
view:@model MyViewModel <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('#yearsddl').change(function () { $(this).closest('form').trigger('submit'); }); }); </script> @using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "data" })) { @Html.DropDownListFor(x => x.Year, Model.Years, new { id = "yearsddl" }) } <table> <thead> <tr> <th>Year</th> <th>Foo</th> <th>Bar</th> </tr> </thead> <tbody id="data"> @Html.Partial("_data", Model.Data ?? Enumerable.Empty<TheData>()) </tbody> </table>
The
jquery.unobtrusive-ajax.js
script inclusion should be moved out of the index view inside the layout for example and the custom js that subscribes for the change event of the dropdownlist should be moved into a separate js file and included from the Layout. I just put them here to illustrate a full example of what's required for the view to work.
_Data.cshtml
partial:@model IList<TheData> @for (int i = 0; i < Model.Count; i++) { <tr> <td>@Html.DisplayFor(x => x[i].Year)</td> <td>@Html.DisplayFor(x => x[i].Foo)</td> <td>@Html.DisplayFor(x => x[i].Bar)</td> </tr> }
相关问答
更多-
我个人更喜欢jQuery,原因如下: - 插件社区更加多样化,吸引了广泛背景的开发人员(而不仅仅是MS堆栈)。 对于MS-AJAX,你现在几乎受限于客户端的用于UI小部件的AJAX控件工具包。 我发现jQuery API远比MS AJAX提供的更适用于常见的客户端任务 鉴于缺乏WebForms MVC中的烟雾和镜像,您有时需要对DOM进行严格的控制才能做某些事情,jQuery提供的CSS选择器引擎确实可以帮助您做到这一点。 就MS AJAX在MVC中提供的内容而言,它可以为您提供一种快速“AJAXify”表 ...
-
在ASP.Net MVC中,ModelState可以与ajax更新一起使用吗?(In ASP.Net MVC, can ModelState be used with an ajax update?)[2021-01-19]
如果我理解你正在尝试做的事情,我的第一个答案将是否定的,你不能使用模型状态,因为它是通过和Ajax请求。 也许你可以模拟ModelState行为,以显示错误: 通过JSON传递List> (属性,消息)(这将要求您将modelErrors从modelState传递到新结构),并通过JS / jQuery完成Validation Summary的HTML构造我认为是杀死解决方案)。 如果您要访问服务器,并且出现任何错误,只需执行Html.Validati ... -
您可以在ASP.NET MVC中使用部分视图来获取类似的行为。 部分视图仍然可以在服务器上构建HTML,您只需要将HTML插入适当的位置(实际上,如果您愿意包含MSFT Ajax库,则MVC Ajax帮助者可以为您设置此选项)。 在主视图中,您可以使用Ajax.Begin窗体来设置异步请求。 <% using (Ajax.BeginForm("Index", "Movie", new AjaxOptions { ...
-
如何在Asp.net MVC 4中使用简单的Ajax Beginform?(How to use Simple Ajax Beginform in Asp.net MVC 4? [closed])[2021-11-26]
简单示例:带有文本框和搜索按钮的表单。 如果您将“名称”写入textbox并提交表单,那么将为患者带来“名称”。 视图: @using (Ajax.BeginForm("GetPatients", "Patient", new AjaxOptions {//GetPatients is name of method in PatientController InsertionMode = InsertionMode.Replace, //target element(#patientList) wi ... -
不要在模型中存储ALL标签列表,只需存储已选择的列表。 将该模型绑定到您的视图。 使用表示标记的字符串参数向控制器添加post方法。 做一些逻辑。 然后将javascript或jquery ajax调用写入该方法,在该方法中传入标记的名称。 如果您的视图需要更新,则可能需要使用ajax调用替换html。 或者你可以通过常规帖子完成所有这些。 这取决于您的需求。 Instead of storing a list of ALL tags in your model, just store a list of ...
-
在asp.net MVC 3中简单的Ajax,更新模型并重新渲染部分(Simple Ajax in asp.net MVC 3, update the model and rerender part)[2022-03-12]
这是一个完整的例子。 模型: public class MyViewModel { public int Year { get; set; } public IEnumerableYears { get { return Enumerable.Range(1980, 40).Select(x => new SelectListItem { ... -
嗯,最明显的问题是,您是否已将脚本添加到您尝试执行此操作的页面中? 其次,如果您要发布到HTTPS(您是,对吗?),您的脚本也必须是HTTPS,否则您将收到安全错误。 This post helped me: http://weblogs.asp.net/owscott/archive/2010/11/17/mvc-3-ajax-redirecting-instead-of-updating-div.aspx
-
使用Ajax的ASP.net MVC(ASP.net MVC with Ajax)[2023-03-31]
斯蒂芬沃尔特刚刚在博客上写了这篇文章: http : //weblogs.asp.net/stephenwalther/archive/2008/09/22/asp-net-mvc-application-building-forums-6-ajax.aspx Stephen Walter just blogged about this: http://weblogs.asp.net/stephenwalther/archive/2008/09/22/asp-net-mvc-application-buil ... -
正如Stephen Muecke所说,您应该在View中更改控制器以传递模型并显示它: 控制器: public PartialViewResult GetExhibitorDataById(int? Id) { List
exhibitors = new List () { new Exhibitor() { Id=1, ... -
当您发布时,您只发送单个ID而不是整个模型,所以基本上这个 public ActionResult Button(MasterM model) will be empty 并且由于您返回空集,因此不会更新文本框。 您可以在此处执行以下操作:1)将接收类型修改为 Public ActionResult Button(int Id) { MasterM model = new MasterM(); model.Id = Id; if (!ModelState.IsVa ...