我的Rails视图中有一个表单字段,如下所示:
<%= f.text_field :date, :class => "datepicker" %>
Run Code Online (Sandbox Code Playgroud)
javascript函数将该类的所有输入字段转换为jQueryUI日期选择器.
$(".datepicker").datepicker({
dateFormat : "dd MM yy",
buttonImageOnly : true,
buttonImage : "<%= asset_path('iconDatePicker.gif') %>",
showOn : "both",
changeMonth : true,
changeYear : true,
yearRange : "c-20:c+5"
})
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.我可以编辑记录,它会将日期正确地保存到数据库中.我的问题是当我想再次编辑记录时.当表单从记录中预先填充时,它以'yyyy-mm-dd'格式显示.javascript只格式化在datepicker控件中选择的日期.有什么办法可以格式化从数据库中检索的日期吗?我可以在哪个阶段这样做?
谢谢,丹妮.
在下面的讨论之后的一些更多细节,我的表单分布在两个文件,一个视图和一个部分.这是观点:
<%= form_tag("/shows/update_individual", :method => "put") do %>
<% for show in @shows %>
<%= fields_for "shows[]", show do |f| %>
<%= render "fields", :f => f %>
<% end %>
<% end %>
<%= submit_tag "Submit"%>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这是_fields …
我是Java的新手,所以我不确定这是否可行.基本上我需要将文件反序列化为给定类型的对象.基本上该方法将执行此操作:
FileInputStream fis = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(fis);
MyClass newObject = (MyClass)in.readObject();
in.close();
return newObject;
Run Code Online (Sandbox Code Playgroud)
我希望这个方法是通用的,因此我可以告诉它我想要in.readObject()将其输出转换为什么类型,并返回它.
希望这是有道理的...然后再说一遍,我可能没有正确理解泛型,这实际上是不可能的,或者是可取的.
感谢:D.
我有以下Coffeescript:
$ ->
$('#new_event').submit ->
$.post(
$(this).attr('action')
$(this).serialize()
(data, textStatus, jqXHR) ->
$('#target').html(data)
)
return false
Run Code Online (Sandbox Code Playgroud)
它转化为:
$(function() {
return $('#new_event').submit(function() {
$.post($(this).attr('action'), $(this).serialize(), function(data, textStatus, jqXHR) {
return $('#target').html(data);
});
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.但是,如何在提交中添加另一行?例如:
$ ->
$('#new_event').submit ->
test = $(this).serialize()
$.post(
$(this).attr('action')
$(this).serialize()
(data, textStatus, jqXHR) ->
$('#target').html(data)
)
return false
Run Code Online (Sandbox Code Playgroud)
这会产生意外的INDENT错误.无法弄清楚我在这里失踪了什么......
谢谢,丹妮.
我有以下脚本:
$ ->
$('#new_event').submit ->
$.post(
$(this).attr('action')
$(this).serialize()
success: (data, textStatus, jqXHR) ->
processData(data, textStatus, jqXHR)
)
return false
processData = (data, textStatus, jqXHR) ->
alert(data)
Run Code Online (Sandbox Code Playgroud)
到目前为止,我不能为我的生活调试这个.它呈现为:
(function() {
var processData;
$(function() {
return $('#new_event').submit(function() {
$.post($(this).attr('action'), $(this).serialize(), {
success: function(data, textStatus, jqXHR) {
return processData(data, textStatus, jqXHR);
}
});
return false;
});
});
processData = function(data, textStatus, jqXHR) {
return alert(data); //BREAKPOINT HERE
};
}).call(this);
Run Code Online (Sandbox Code Playgroud)
哪个看起来对我好.如果我把断点放在alert它上面永远不会停止.我的javascript知识非常有限,所以我显然在这里遗漏了一些东西.很想知道发生了什么.
谢谢,丹妮.
我试图使用ASP.NET MVC的jQuery Grid插件来显示数据.看来web上提供的示例显示控制器动作签名如下所示:
public ActionResult SomeMethod(string sidx, string sord, int page, int rows) { }
Run Code Online (Sandbox Code Playgroud)
有什么办法可以从页面上的各个输入字段传递额外的参数吗?
干杯,D.
补充:我还没有编写任何代码,但客户端代码将是这样的:
jQuery(document).ready(function(){
jQuery("#list").jqGrid({
url:'/Entry/GridData/',
datatype: 'json',
mtype: 'POST',
colNames:['Entry Date','Registration','Registered Name'],
colModel :[
{name:'EntryDate', index:'EntryDate', width:40 },
{name:'Registration', index:'Registration', width:200 },
{name:'RegisteredName', index:'RegisteredName', width:200 }],
pager: jQuery('#pager'),
rowNum:20,
rowList:[5,10,20,50],
altRows: true,
sortable: false,
viewrecords: true,
caption: 'My first grid'
});
});
Run Code Online (Sandbox Code Playgroud)
服务器端代码如下:
public ActionResult GridData(string sidx, string sord, int page, int rows)
{
//Some stuff to get data, which needs a couple of …Run Code Online (Sandbox Code Playgroud) 我刚刚开始尝试使用Web Api 2和StructureMap,已经安装了StructureMap.MVC4 Nuget包.在我尝试注册用户之前,一切似乎都运行良好.当IHttpControllerActivator的这个实现试图实例化一个控制器时,我得到了这个错误:
public class ServiceActivator : IHttpControllerActivator
{
public ServiceActivator(HttpConfiguration configuration) { }
public IHttpController Create(HttpRequestMessage request
, HttpControllerDescriptor controllerDescriptor, Type controllerType)
{
var controller = ObjectFactory.GetInstance(controllerType) as IHttpController;
return controller;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
StructureMap Exception Code: 202
No Default Instance defined for PluginFamily Microsoft.AspNet.Identity.IUserStore`1[[Microsoft.AspNet.Identity.EntityFramework.IdentityUser, Microsoft.AspNet.Identity.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], Microsoft.AspNet.Identity.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Run Code Online (Sandbox Code Playgroud)
我理解错误是什么,但不完全确定如何解决它.假设StructureMap中的默认扫描程序找不到IUserStore的默认实现是否正确?这是我使用的初始化代码:
ObjectFactory.Initialize(x => x.Scan(scan =>
{
scan.AssembliesFromApplicationBaseDirectory();
scan.WithDefaultConventions();
}));
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?谢谢.
编辑:我想我可能用这个解决了最初的问题:
x.For<Microsoft.AspNet.Identity.IUserStore<IdentityUser>>()
.Use<UserStore<IdentityUser>>();
Run Code Online (Sandbox Code Playgroud)
但现在还有另一个默认实例StructureMap无法解决 - dbcontext.这是我收到的下一条错误消息:
ExceptionMessage=StructureMap Exception Code: 202
No Default Instance defined for …Run Code Online (Sandbox Code Playgroud) structuremap dependency-injection basic-authentication asp.net-web-api
我是Coffeescript的新手,想在jquery 1.6.4中使用delegate()方法.方法签名是.delegate( selector, eventType, handler ).我如何在Coffeescript中调用此方法?我正在使用Rails 3.1.
谢谢,丹妮.
我已按如下方式更改了我的 Powershell 配置文件,以在 posh-hg 提示符中包含日期时间:
if(!(Test-Path function:\TabExpansion)) { New-Item function:\Global:TabExpansion -value '' | Out-Null }
# Load posh-hg example profile
. 'C:\ProgramData\chocolatey\lib\Posh-HG\JeremySkinner-posh-hg-e273b0d\profile.example.ps1'
Rename-Item Function:\Prompt PoshHGPrompt -Force
function Prompt() {if(Test-Path Function:\PrePoshHGPrompt){++$global:poshScope; New-Item function:\script:Write-host -value "param([object] `$object, `$backgroundColor, `$foregroundColor, [switch] `$nonewline) " -Force | Out-Null;$private:p = PrePoshHGPrompt; if(--$global:poshScope -eq 0) {Remove-Item function:\Write-Host -Force}}PoshHGPrompt}
$global:HgPromptSettings.BeforeText = " [$(Get-Date -format g)] `n["
Run Code Online (Sandbox Code Playgroud)
由于某种原因,日期根本没有更新。我怀疑这可能与 posh-hg 如何构建提示有关,但这有点疯狂的猜测。
jquery ×4
coffeescript ×3
android ×1
asp.net-mvc ×1
generics ×1
java ×1
jqgrid ×1
jquery-ui ×1
mercurial ×1
powershell ×1
structuremap ×1