jQueryUI DatePicker自定义年份(jQueryUI DatePicker Customizing the Year)
我有一个使用jqueryui DatePicker的Datepicker。
行为要求是:
用户可以为朋友存储出生日期。 用户应该能够存储一年(如果已知),或选择“N / A”。
如果选择“N / A”,则将1900年存储在数据库中,并仅在输入字段中向用户显示日期和月份。
下拉列表应该从1950年开始,但显示从当前日期开始的过去100年(< - 这将是锦上添花,否则从当年开始,如果有必要,可以追溯到1900年)
这是我到目前为止所获得的,但它是kludgey ......这是轻描淡写。 并且出于某种原因,如果用户选择日期,但不改变年份下拉列表,则存储当前年份,而不是1900年。
(它是在json调用的上下文中)。 当然有更好的方法。
var birthday_options = {changeMonth: true, changeYear: true, yearRange: '1900:2010', onClose: function(dateText, inst) { contact.field_updater('birthday').call(this); $('input.mng-birthday').val(function(i, val) { return val.replace('/1900', ''); }); }, beforeShow: function (input) { setTimeout(function () { $('select.ui-datepicker-year option:first').text('N/A'); }, 1); }}, .find('.mng-birthday').val(data.birthday || 'Unknown') .datepicker(birthday_options) .end();
I have a Datepicker using jqueryui DatePicker.
The behavior requirement is:
A User can store a Birthdate for a friend. The User should be able to store a year if known, or select "N/A".
If "N/A" is selected, Store the year 1900 in the database and only display the day and month in an input field to the User.
The dropdown should start at 1950 but show the past 100 years from current date (<-- this would be icing on the cake, otherwise start at current year and if necessary go back to 1900)
Here's what I got so far, but it's kludgey...and that's an understatement. And for some reason, if the user selects a date, but doesn't alter the year dropdown, then the current year is stored, rather than 1900.
(it's in the context of a json call). Surely there's a better way.
var birthday_options = {changeMonth: true, changeYear: true, yearRange: '1900:2010', onClose: function(dateText, inst) { contact.field_updater('birthday').call(this); $('input.mng-birthday').val(function(i, val) { return val.replace('/1900', ''); }); }, beforeShow: function (input) { setTimeout(function () { $('select.ui-datepicker-year option:first').text('N/A'); }, 1); }}, .find('.mng-birthday').val(data.birthday || 'Unknown') .datepicker(birthday_options) .end();
原文:https://stackoverflow.com/questions/4045680
最满意答案
我认为正确的方法是由rawr发布的,但仅仅是为了完整性:
基础包:
df <- merge(df1, df2, all =TRUE, na.rm =TRUE ) df[!duplicated(df$Virus),]
dplyr:
library(dplyr) full_join(df1, df2) %>% arrange(X.7) %>% distinct(Virus) # or full_join(df1, df2) %>% filter(!duplicated(Virus, fromLast = TRUE))
sqldf:
sqldf("SELECT min(Virus) AS Virus, [X.7], [X.6] FROM (SELECT * FROM df2 AS t1 UNION ALL SELECT * FROM df1 AS t2) GROUP BY Virus")
输出:
Virus X.7 X.6 1 FCrisp 23.05 111.01 2 InkLog 33.00 22.00 3 RCrisp NA NA 4 ZCrisp NA NA
数据 :
df1 <- structure(list(Virus = structure(c(2L, 3L, 1L, 4L), .Label = c("FCrisp", "InkLog", "RCrisp", "ZCrisp"), class = "factor"), X.7 = c(NA, NA, NA, NA), X.6 = c(NA, NA, NA, NA)), .Names = c("Virus", "X.7", "X.6"), class = "data.frame", row.names = c(NA, -4L)) df2 <- structure(list(Virus = structure(c(2L, 1L), .Label = c("FCrisp", "InkLog"), class = "factor"), X.7 = c(33, 23.05), X.6 = c(22, 111.01)), .Names = c("Virus", "X.7", "X.6"), class = "data.frame", row.names = c(NA, -2L))
I think the right approach was posted by rawr, but just for completeness’ sake:
Base package:
df <- merge(df1, df2, all =TRUE, na.rm =TRUE ) df[!duplicated(df$Virus),]
dplyr:
library(dplyr) full_join(df1, df2) %>% arrange(X.7) %>% distinct(Virus) # or full_join(df1, df2) %>% filter(!duplicated(Virus, fromLast = TRUE))
sqldf:
sqldf("SELECT min(Virus) AS Virus, [X.7], [X.6] FROM (SELECT * FROM df2 AS t1 UNION ALL SELECT * FROM df1 AS t2) GROUP BY Virus")
Output:
Virus X.7 X.6 1 FCrisp 23.05 111.01 2 InkLog 33.00 22.00 3 RCrisp NA NA 4 ZCrisp NA NA
Data:
df1 <- structure(list(Virus = structure(c(2L, 3L, 1L, 4L), .Label = c("FCrisp", "InkLog", "RCrisp", "ZCrisp"), class = "factor"), X.7 = c(NA, NA, NA, NA), X.6 = c(NA, NA, NA, NA)), .Names = c("Virus", "X.7", "X.6"), class = "data.frame", row.names = c(NA, -4L)) df2 <- structure(list(Virus = structure(c(2L, 1L), .Label = c("FCrisp", "InkLog"), class = "factor"), X.7 = c(33, 23.05), X.6 = c(22, 111.01)), .Names = c("Virus", "X.7", "X.6"), class = "data.frame", row.names = c(NA, -2L))
相关问答
更多-
这看起来像我们在这里多次使用的连接更新。 update old set NewID = new.NewID from ContactRecords as old inner join NewContact as New on new.OriginalID = old.OriginalID This looks like a join update which we had here many times. update old set NewID = new.NewID from ContactRec ...
-
这应该在C#中完成: var query = from log in db.CafeLogs join emp in db.Employees on log.EmployeeId equals emp.EmployeeId join cas in db.Employees on log.CashierId equals cas.EmployeeId select new { lo ...
-
看起来并不那么容易: set它会更新主网格,从而导致刷新,然后折叠所有行。 在set之后扩展行(使用expandRow )并不简单:使用parentRow调用grid.expandRow(parentRow); 不起作用,因为它刷新主时HTML似乎更改,然后不再有效。 所以似乎 parentRow是保存行的uid并使用它来再次查找parentRow并展开它。 就像是: click: function (e) { var parentRow = $(e.target).closest(".k-deta ...
-
尝试 SELECT B1.customerid, B1.stype, D1.day FROM Book B1 INNER JOIN Timetable T1 on T1.timeslotid=B1.timeslotid INNER JOIN Days D1 on D1.dayslotsid=T1.dayslotid; 从您的查询开始,我将D1上的连接条件从D1.dayslotsid=B1.timeslotid为D1.dayslotsid=T1.dayslotid并根据您的示例将B1.stype添加到字段选 ...
-
如何基于同一列显示Code_Master表中的多个代码(How to display multiple codes from a Code_Master table based on the same column)[2023-05-28]
您可以多次加入同一个表。 我想你想要这样的东西: select ... n.Note_Category nc.Code_Description as Note_Category_Description, ... n.Caller_Mood, cm.Code_Description as Caller_Mood_Description, ... from Notes n join Code_Master nc on nc.Code_Id = n.Note ... -
创建主表组件并以角度动态添加子列(Create a master table component and add child columns dynamically in angular)[2022-07-20]
基本上,您必须创建主master-table组件和通用列表chid-column组件,并将其插入父html模板结构中。 我以更好的理解方式编辑最后一部分希望...... 然后你可以构建你的子组件以包含你需要的所有属性,并且感谢*ngIf只显示你从提供者方法返回的属性,即getClients() , getUsers() , getHouses() ,还要感谢@Input装饰你可以直接从父级向子级注入此数据,只需更改数据即可创建所需的许多组件。 所以在你的父母那里你可以有类似的东西 import { Comp ... -
我认为正确的方法是由rawr发布的,但仅仅是为了完整性: 基础包: df <- merge(df1, df2, all =TRUE, na.rm =TRUE ) df[!duplicated(df$Virus),] dplyr: library(dplyr) full_join(df1, df2) %>% arrange(X.7) %>% distinct(Virus) # or full_join(df1, df2) %>% filter(!duplicated(Virus, fromLast = TR ...
-
Insert Table2( Column1 ) Select Column1 From Table1 As T1 Where Not Exists ( Select 1 From Table2 As T2 Where T2.Column1 = T1.Column1 ) Insert Table2( Column1 ) Select Colu ...
-
基于一列的两个表组合,其中重复值获得自己的列(Combining Two Tables Based on One Column Where Duplicate Values Get Their Own Column)[2023-04-27]
这正是您所需要的: with m as ( select ROW_NUMBER() over (partition by id order by data) as Nr, table_1.id, table_1.data from table_1 ) select table_2.id, m1.data as Mail1, m2.data as Mail2, m3.data as Mail3, m4.data as Mail4 from table_2 ... -
如何在插入两个表然后触发异常时知道表名(How to know table name when inserting into two tables then triggering an exception)[2022-04-14]
如果要跟踪导致错误的查询,请使用全局变量来定义查询语句。 当引发异常时,您可以使用相同的变量来调试它。 示例 : globalVar = "" try: ... cur = conn.cursor() globalVar = "insert into table_A values ( %s, %s )" cur.execute( globalVar, ( value_1, value_2 ) ) print "Row inserted in table_A" /* ...