简体   繁体   English

停用p:calendar中的特定日期?

[英]Disable specific days in p:calendar?

I am working on Primefaces in JSF , i am just trying to disable all sundays in calendar, 我正在使用JSF开发Primefaces ,我只是想禁用日历中的所有星期天,

How can i do it,, 我该怎么做,,

  • As i referred sites, i got a point we can achieve it using beforeShowDay but i don't know how to use it. 当我提到站点时,我很beforeShowDay我们可以使用beforeShowDay实现它,但是我不知道如何使用它。
  • Primefaces user guide page 10 explains it, but i don't understand what they trying to say. Primefaces用户指南第10页对此进行了说明,但我不明白他们想说什么。

     <p:calendar value="#{dateBean.date}" beforeShowDay="tuesdaysAndFridaysOnly" /> function tuesdaysAndFridaysDisabled(date) { var day = date.getDay(); return [(day != 2 && day != 5), ''] } 

In above code they are calling the function tuesdaysAndFridaysDisabled from beforeShowDay but my question is 在上面的代码中,他们从beforeShowDay调用函数tuesdaysAndFridaysDisabled ,但是我的问题是

  • They are calling the function name as tuesdaysAndFridaysOnly but how it will affect the function tuesdaysAndFridaysDisabled 他们将函数名称称为tuesdaysAndFridaysOnly但是它将如何影响函数tuesdaysAndFridaysDisabled

And it not working too.. How to achieve it and what is happening there.. 而且它也不起作用..如何实现它以及那里发生了什么..

This is an error in the Primefaces documentation. 这是Primefaces文档中的错误。 They function tuesdaysAndFridaysDisabled should be called instead of tuesdaysAndFridaysOnly , which is a javascript function you can call to customize the date. 它们的功能tuesdaysAndFridaysDisabled应该被称为取代tuesdaysAndFridaysOnly ,这是一个javascript函数可以调用自定义的日期。

So the correct source code would look like 所以正确的源代码看起来像

<p:calendar value="#{dateBean.date}" beforeShowDay="tuesdaysAndFridaysDisabled" />

And within the function tuesdaysAndFridaysDisabled you can do whatever you want with the provided parameter date. 在函数tuesdaysAndFridaysDisabled您可以使用提供的参数date进行任何操作。 In this case the tuesdays ( 2 ) and fridays ( 5 ) are disabled. 在这种情况下,星期二( 2 )和星期五( 5 )被禁用。

function tuesdaysAndFridaysDisabled(date)
{
  var day = date.getDay();
  return [(day != 2 && day != 5), '']
}

The documentation states: 该文档指出:

The function returns an array with two values, first one is flag to indicate if date would be displayed as enabled and second parameter is the optional style class to add to date cell. 该函数返回一个带有两个值的数组,第一个是标志,指示是否将日期显示为启用状态,第二个参数是要添加到日期单元格的可选样式类。

As you can see. 如你看到的。 If the date is a tuesday or friday, the first parameter in the returned array is false , which means that these days won't be selected within the p:calendar . 如果date是星期二或星期五,则返回数组中的第一个参数为false ,这意味着将不会在p:calendar选择这些p:calendar

Update: You can find a similar question here: Disable specific dates on p:calendar . 更新:您可以在此处找到类似的问题: 在p:calendar上禁用特定日期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM