首页 \ 问答 \ jQueryUI DatePicker自定义年份(jQueryUI DatePicker Customizing the Year)

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
更新时间:2022-09-07 12:09

最满意答案

我认为正确的方法是由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))

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。