小编Cam*_*ron的帖子

简单的PHP随机数组

我有一个像这样的简单数组:

$input = array('Line1', 'Line2', 'Line3');
Run Code Online (Sandbox Code Playgroud)

并希望随机回应其中一个值.我以前做过这个,但是不记得我是怎么做到的,所有array_rand的例子看起来都比我需要的更复杂.

有什么帮助吗?谢谢

php arrays

7
推荐指数
1
解决办法
2万
查看次数

jQuery显示DIV并滚动到它而没有url中的hashtag

我有以下简单的jQuery:

            $('#features').hide();

            $('#more').click(function(e)
            {
                e.preventDefault();
                $('#more').hide();
                $('#features').show();
            });
Run Code Online (Sandbox Code Playgroud)

这显示了当用户单击更多链接并使用preventDefault方法时,#features哈希未添加到URL 的DIV .但是我仍然想要向下滚动到那个DIV,就像将哈希传递给url一样,只是不在地址栏中显示它.我该怎么做呢?谢谢

注意:我不是在寻找任何奇特的效果等,所以不要使用像scrollTo等插件

hash jquery

7
推荐指数
1
解决办法
5838
查看次数

jQuery Tablesorter未捕获TypeError:无法设置未定义的属性'count'

我正在使用jQuery TableSorter插件并Uncaught TypeError: Cannot set property 'count' of undefined使用此代码获得以下错误:

$(document).ready(function () {
    var copyThead = $(".uiGridContent thead").html();
    copyThead = '<table><thead>' + copyThead + '</thead></table>';
    $(".uiGridHeader").html(copyThead);
    $(".uiGridContent table").tablesorter();
    $(".uiGridContent table thead").hide();
    $(".uiGridHeader th").click(function () {
        // Get updated HTML
        var FindcopyThead = $(".uiGridContent thead").html();
        var NewcopyThead = '<table><thead>' + FindcopyThead + '</thead></table>';
        $(".uiGridHeader").html(NewcopyThead);

        var index = $(".uiGridHeader th").index(this);
        var sorting = [[index, 0]];
        $(".uiGridContent table").trigger("sorton", [sorting]);
        return false;
    });
});
Run Code Online (Sandbox Code Playgroud)

而HTML是:

<div class="uiGrid">
    <div class="uiGridHeader">
        <!-- NEW HEADER GOES …
Run Code Online (Sandbox Code Playgroud)

jquery tablesorter

7
推荐指数
1
解决办法
5956
查看次数

使用jQuery AJAX显示正确的错误消息

目前,如果我有一个ajax请求的错误,如提交表单(我使用的是ASP.NET MVC 3),它将显示类似"内部服务器错误"的内容.

但是如果我在不使用Ajax的情况下进行提交,则.net将显示实际的服务器错误.

关于我怎么可能得到错误显示的任何想法?所以我的用户可以报告问题而不是只能说"内部服务器错误"

谢谢

jquery

7
推荐指数
2
解决办法
3万
查看次数

CakePHP使用%like%查找查询

我有以下查找我的CakePHP应用程序的查询:

$this->paginate = array(
'limit'=>5,
'order'=>'Note.datetime DESC',
'conditions' => array(
    'Note.status'=>1,
    'OR' => array(
        'Note.title LIKE' => '%'. $q . '%',
        'Note.content LIKE' => '%'. $q . '%'
        )
    )
);
Run Code Online (Sandbox Code Playgroud)

其中一个参数被称为$q像标题和内容上的查询一样.

例如,如果我有以下内容:

Title: Lorem ipsum Content: Lorem ipsum dolare

并寻找 'lorem'

它会发现很好.但如果我搜索'lorem dolare'它将无法找到它.

我怎么做?

注意:我不想使用任何插件等.

编辑:如果我使用FULLTEXT这会工作吗?

$this->paginate = array(
'limit'=>5,
'order'=>'Note.datetime DESC',
'conditions' => array(
    'Note.status'=>1,
    'OR' => array(
        'MATCH(Note.title) AGAINST('.$q.' IN BOOLEAN MODE)',
        'MATCH(Note.content) AGAINST('.$q.' IN BOOLEAN MODE)'
        )
    )
);
Run Code Online (Sandbox Code Playgroud)

编辑2:

尝试以上操作时出现此错误:

 Error: …
Run Code Online (Sandbox Code Playgroud)

php mysql cakephp

7
推荐指数
2
解决办法
2万
查看次数

jQuery UI Datepicker显示不正确的周数

使用jQuery UI Datepicker并在星期日开始一周时,周数不正确.例如,2016年1月3日应该是第1周,因为所有日期(第3天到第9天)都在同一年.但正如您在下面的屏幕截图中看到的那样,UI将其显示为第53周.

在此输入图像描述

以下是呈现datepicker的代码:

$("#datepicker" ).datepicker({
    showWeek: true,
    firstDay: 0
});
Run Code Online (Sandbox Code Playgroud)

所以没有什么特别的,除了显示周数和周日开始周而不是周一(默认情况下).

这是一个问题的小提琴:https://jsfiddle.net/vLqabmmz/

javascript jquery jquery-ui datepicker

7
推荐指数
1
解决办法
2272
查看次数

ngRepeat中的等于什么?

是什么在等号ng-repeat的属性值是什么意思?

<li ng-repeat="person in people = (people | orderBy: firstname)">
Run Code Online (Sandbox Code Playgroud)

而不是做:

<li ng-repeat="person in people | orderBy: firstname">
Run Code Online (Sandbox Code Playgroud)

我看不到任何解释它在ngRepeat文档中使用的例子.

javascript angularjs

7
推荐指数
1
解决办法
210
查看次数

将ActionCable发送给特定用户

我有以下代码在我的Rails应用程序中发送ActionCable广播: ActionCable.server.broadcast 'notification_channel', notification: 'Test message'

连接如下:

module ApplicationCable
  class Connection < ActionCable::Connection::Base

    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    def session
      cookies.encrypted[Rails.application.config.session_options[:key]]
    end

    protected

    def find_verified_user
      User.find_by(id: session['user_id'])
    end

  end
end
Run Code Online (Sandbox Code Playgroud)

但是,登录应用程序的所有用户都将收到它.该identified_by只可以确保登录的用户可以连接到该通道,但它并没有限制哪些用户获得广播.

有没有办法只向某个用户发送广播?

我能想到的唯一方法是:

ActionCable.server.broadcast 'notification_channel', notification: 'Test message' if current_user = User.find_by(id: 1)
Run Code Online (Sandbox Code Playgroud)

其中1是我想要定位的用户的ID.

ruby-on-rails

7
推荐指数
2
解决办法
2073
查看次数

ASP.NET MVC将datetime作为查询传递

我如何传递日期时间,例如01/01/2011 21:01:34作为查询字符串?

我正在建立一个剧院预订网站,当我观看表演时,我目前通过了演出和场地,但也需要通过日期(因为这是演出的独特部分)

ActionResult看起来像这样:

public ActionResult Details(String name, String venue, String date)
{
    return View(_repository.performanceDetails(name, venue, date));
}
Run Code Online (Sandbox Code Playgroud)

但是performanceDate不会工作,因为它是一个日期时间数据类型!我需要做的是删除数据的时间部分,例如00:00:00并以某种方式将剩余数据作为字符串传递,我可以用它来比较,如下所示:

public PerformanceDetails performanceDetails(String name, String venue, String date)
{
    var PerformanceDetails = (from s in _db.PerformanceDetails
                              where s.show == name && 
                                    s.venue == venue && 
                                    s.performanceDate == date
                              select s).First();
    return PerformanceDetails;
}
Run Code Online (Sandbox Code Playgroud)

这是一个示例链接:

<%= Html.ActionLink("View Details", "Details", "Performances", 
                    new { 
                        name = item.show, 
                        venue = item.venue, 
                        date = item.performanceDate }, 
                    new {@class = "button"}) …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

6
推荐指数
2
解决办法
1万
查看次数

如何运行名​​称空间内的JavaScript函数

如果我有类似的东西:

App = {
    editingMode: function ()
    {
        function setEditingMode(entityID) {
            $('#editingMode').val('1');
            $.ajax({
                type: "POST",
                url: "/Organisations/Manage/LockEntity/",
                data: "entityID=" + entityID
            });
        }
        function setEditingModeOff(entityID) {
            if ($("#myform").valid() == true)
            {
                $('#editingMode').val('0');
                $.ajax({
                    type: "POST",
                    url: "/Organisations/Manage/UnlockEntity/",
                    data: "entityID=" + entityID
                });
            }
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

我如何运行其中一个内部函数?

App.editingMode();但那我该怎么办呢setEditingMode

javascript

6
推荐指数
2
解决办法
452
查看次数