小编pea*_*ove的帖子

如何检查是否存在多个数组键?

有没有更简单、更聪明、更清晰的方法来写这个?

if (array_key_exists("name", $array) AND array_key_exists("age", $array) AND array_key_exists("size", $array) AND array_key_exists("gender", $array) {
    echo "Keys exist!";
}
Run Code Online (Sandbox Code Playgroud)

php

3
推荐指数
1
解决办法
3630
查看次数

如何在期权变更上创建div?

我想colors通过选项创建具有类名的div .on("change").它运作良好,但只要我改变选项,就会div创建越来越多的选项.但我只有两个colors,所以任何时候我改变选项,我只想看到两个div:"蓝色"和"红色".我试图$('.result').remove();在追加之前使用.但是没有附加任何内容.

$(document).ready(function() {
  $("#select").on("change", function() {
    $(".colors").each(function() {
      var color = $(this).attr('title');
      $(".result").append("<div>" + color + "</div>");
    });
  });
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<select id="select">
  <option class="colors" title="blue">a</option>
  <option class="colors" title="red">b</option>
  <option title="green">c</option>
</select>

<div class="result"></div>
Run Code Online (Sandbox Code Playgroud)

jquery

3
推荐指数
1
解决办法
48
查看次数

如何在每个 select2 选择框周围设置边框?

我想用 jQuery 在我的每个选择框周围设置一个红色边框。但它不起作用:

http://jsfiddle.net/jEADR/3795/

<script type="text/javascript" src="//code.jquery.com/jquery-1.8.3.js"></script> 
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.min.js"></script>
 <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.css">

<select class="select" style="width:300px">
        <option value="AL">Alabama</option>
        <option value="Am">Amalapuram</option>
        <option value="An">Anakapalli</option>
        <option value="Ak">Akkayapalem</option>
        <option value="WY">Wyoming</option>
    </select>
    <select class="select" style="width:300px">
        <option value="AL">Alabama</option>
        <option value="Am">Amalapuram</option>
        <option value="An">Anakapalli</option>
        <option value="Ak">Akkayapalem</option>
        <option value="WY">Wyoming</option>
    </select>

<script>
    $(".select").select2();
    $(".select").each(function() {
    $(this).siblings().find(".select2-container").css({"border-color": "red", "border-weight":"5px", "border-style":"solid"});
    });
</script>
Run Code Online (Sandbox Code Playgroud)

jquery select2

3
推荐指数
1
解决办法
5248
查看次数

如何在dataTables中使用select2选择框?

我想在我的bootstrap数据表中使用select2选择框.我需要使用完整的select2 js(https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.js)但它不起作用,我想知道为什么.

$(document).ready(function() {
    var table = $('#example').DataTable( {
        scrollY:        "300px",
        scrollX:        true,
        scrollCollapse: true,
        paging:         false,
        fixedColumns:   {
            leftColumns: 1,
            rightColumns: 1
        }
    } );
} );

$("#e1").select2();
Run Code Online (Sandbox Code Playgroud)
td, th{background-color:white;}
Run Code Online (Sandbox Code Playgroud)
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>

<link href="http://cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.css" rel="stylesheet"/>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/fixedcolumns/3.2.2/js/dataTables.fixedColumns.min.js"></script>

<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>


<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.js"></script>


<table id="example" class="stripe row-border order-column" width="100%" cellspacing="0">
        <thead>
            <tr>
                <th>First name</th>
                <th>Last name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
                <th>Extn.</th>
                <th>E-mail</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><select  id="e1">
        <option value="AL">Alabama</option>
        <option value="Am">Amalapuram</option> …
Run Code Online (Sandbox Code Playgroud)

jquery datatables jquery-select2

3
推荐指数
1
解决办法
6526
查看次数

如何通过 Symfony 4 连接到使用 MAMP 创建的 mySQL 数据库?

我在 MAMP 中创建了一个名为“project”的数据库。

在我的.env文件中,我添加了这一行:

DATABASE_URL=mysql://root:root@localhost:3306/project
Run Code Online (Sandbox Code Playgroud)

现在我想跑

php bin/console doctrine:database:create
Run Code Online (Sandbox Code Playgroud)

但我收到一条错误消息:

SQLSTATE[HY000] [2002] 没有那个文件或目录

我的学说配置:

parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    env(DATABASE_URL): ''

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci

        url: '%env(resolve:DATABASE_URL)%'
    orm: …
Run Code Online (Sandbox Code Playgroud)

mysql doctrine database-connection symfony

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

如何使用序列化器(Symfony 4)创建正确格式的 json 字符串?

我正在使用序列化器创建一个 json 字符串:

$table = $this->getDoctrine()->getRepository(Article::class)->findAll();

$serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
$json_string = $serializer->serialize($table, 'json');
Run Code Online (Sandbox Code Playgroud)

$表的结果:

array(2) { [0]=> object(App\Entity\Article)#5975 (3) { ["id":"App\Entity\Article":private]=> int(1) ["title":"App\Entity\Article":private]=> string(9) "Article 1" ["body":"App\Entity\Article":private]=> string(32) "This is the body for article one" } [1]=> object(App\Entity\Article)#5979 (3) { ["id":"App\Entity\Article":private]=> int(2) ["title":"App\Entity\Article":private]=> string(11) "Article Two" ["body":"App\Entity\Article":private]=> string(32) "This is the body for article two" } } 
Run Code Online (Sandbox Code Playgroud)

这是 $json_string 的结果:

string(145) "[{"id":1,"title":"Article 1","body":"This is the body for article one"},{"id":2,"title":"Article Two","body":"This is the body for …
Run Code Online (Sandbox Code Playgroud)

serialization json encode doctrine symfony

3
推荐指数
1
解决办法
1683
查看次数

如何将文本限制为仅限200个字符?

我不知道,为什么我看不到任何文字:

$(".elipsis").text($(this).text().substr(0, 200)+'...');
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

 <p class="elipsis">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. …
Run Code Online (Sandbox Code Playgroud)

jquery

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

如何将多列数据呈现为一列?

我想将来自两个不同列的值呈现到我的jquery数据表中

https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js
https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css

$(document).ready(function(){

    var table = $('#table').DataTable({

         "ajax": {
                "url": "data.json",
                "dataSrc": "",
            },

         "columnDefs": [
            {
               "render": function (data, type, row) {
                   var result = 'The id is ' + data[0] + ' and the name is ' + data[1];
                        return result;
                    },
                    "targets": 0,
                },      

         ],

        "columns": [
                {
                    "data": "id"
                },
                {
                    "data": "name"
                }
            ]
    });

});
Run Code Online (Sandbox Code Playgroud)

data.json:

[{
    "id": "12",
    "name": "Laura"
}]
Run Code Online (Sandbox Code Playgroud)

但是我的结果是:

The id is 12 and the name is undefined
Run Code Online (Sandbox Code Playgroud)

ajax jquery datatables

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

如何使 atom-beautify 与 php 文件中的 html 一起使用?

我在 Atom 编辑器中安装了 atom-beautify 包。

我打开一个文件 index.php

 <ul>
 <li>Coffee</li>
        <li>Tea</li>
  <li>Milk</li>
        </ul> 
Run Code Online (Sandbox Code Playgroud)

然后我发出“美化”命令。

但我的代码仍然是这样的:

 <ul>
 <li>Coffee</li>
        <li>Tea</li>
  <li>Milk</li>
        </ul> 
Run Code Online (Sandbox Code Playgroud)

我希望代码更改为:

 <ul>
   <li>Coffee</li>
   <li>Tea</li>
   <li>Milk</li>
 </ul> 
Run Code Online (Sandbox Code Playgroud)

html php auto-indent atom-editor atom-beautify

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

如何忽略 git 中的 .env 文件?

我在 .env 文件中进行了更改,然后在终端中写入git status

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   .env
Run Code Online (Sandbox Code Playgroud)

我希望 .env 文件中的更改被 git 忽略,所以我在 .gitignore 中添加了这一行:

/.env
Run Code Online (Sandbox Code Playgroud)

现在当我写的时候git status我得到的结果是:

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   .env
    modified:   .gitignore
Run Code Online (Sandbox Code Playgroud)

我现在能做什么?为什么 gitignore 没有被忽略?

git gitignore

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