小编And*_*lis的帖子

Vue.js为空过滤结果

在Vue中,我必须过滤一些数据:

<input v-model="search">
<ul>
    <li v-repeat="photo in photos | filterBy search in 'name'">
        <img src="{{ photo.src }}" alt="{{ photo.name }}">
    </li>
    <li v-if="!photos.length">
        No results, sorry!
    </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

如何检测空的过滤器结果并向用户显示相应的消息?

编辑

我目前正在做以下工作,我觉得这是一个hacky解决方法:

HTML:

<input v-model="search">
<ul>
    <li v-repeat="photo in photos">
        <img src="{{ photo.src }}" alt="{{ photo.name }}">
    </li>
    <li v-if="!photos.length">
        No results, sorry!
    </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

var v = new Vue({
    data: {
        allPhotos: [...],
        photos: [],
        search: '',
    },
    ready: function () {
        var filter = Vue.filter('filterBy');
        var self = …
Run Code Online (Sandbox Code Playgroud)

vue.js

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

检索Laravel Eloquent中的所有morphedByMany关系

在Laravel文档中,有以下用于检索morphedByMany关系的示例,它们是多对多的多态关系.

Laravel多对多的多态关系文档

namespace App;

use Illuminate\Database\Eloquent\Model;

class Tag extends Model
{
    /**
     * Get all of the posts that are assigned this tag.
    */
    public function posts()
    {
        return $this->morphedByMany('App\Post', 'taggable');
    }

    /**
     * Get all of the videos that are assigned this tag.
     */
    public function videos()
    {
        return $this->morphedByMany('App\Video', 'taggable');
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎么会得到所有的列表morphed关系在一个查询/集,例如,postsvideos,然后如果我后来添加photos(或任何东西),即得?

php polymorphism laravel eloquent

16
推荐指数
1
解决办法
2749
查看次数

Google Places JavaScript自动填充功能:我可以从地名中删除国家/地区吗?

我有以下jQuery代码,可以很好地获取所选国家/地区的城市列表.

var city;   var place;

$('#city').on('focus',function(){
    input = this, options = {
        types: ['(cities)'],
        componentRestrictions: {
            country: $('#country option:selected').val()
            }
    };
    city = new google.maps.places.Autocomplete(input, options);
    google.maps.event.addListener(city, 'place_changed', function() {
        place = city.getPlace();
        $(input).val(place.address_components[0].long_name);
    })
})
Run Code Online (Sandbox Code Playgroud)

基本上,一旦人选择了该位置,它就会将输入框中的值替换为没有国家/地区的"城市"值.

City, Country当用户已经选择了一个国家时,在下拉菜单中看起来有点愚蠢,如果您已经定义了componentRestrictions将结果限制在某个国家/地区,是否有人知道是否可以显示城市名称?

一旦选择有点......我找到了我当前设置它的方法......真的很垃圾......

javascript google-maps google-places-api

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

Laravel Eloquent查询关系

我为我正在研究的项目创建了一个消息传递系统,似乎已经遇到了一些绊脚石.

我有以下表结构(为清楚起见省略了无关列)

messages
-------------------------
from_id    to_id    spam

users
-------------------------
id    group_id

groups
-------------------------
id    access_level
Run Code Online (Sandbox Code Playgroud)

访问级别使用按位权限

001 read
010 write
100 delete
Run Code Online (Sandbox Code Playgroud)

所以要读写,访问级别为'3'

用户可以拥有网站管理员撤销的权限,因此我要做的是选择已发送给发件人仍具有写权限的用户的邮件.

我的模型设置如此(仅显示相关部分)

class User extends Eloquent {
    public function group() {
        return $this->belongsTo('Group');
    }
}

class Message extends Eloquent {
    public function to() {
        return $this->belongsTo('User', 'to_id');
    }
    public function from() {
        return $this->belongsTo('User', 'from_id');
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试了以下内容

Message::with(['from' => function($query)
{
    $query->with(['group' => function($_query)
    {
        $_query->where('access_level', '&', 2);
    }]);
}])
->where('to_id', Auth::user()->id)
->get();
Run Code Online (Sandbox Code Playgroud)

这将获取发送给当前登录用户的消息,其中发件人组的访问级别仍然允许用户写入消息(理论上),但它只是返回发送给用户的所有消息.

我还试图专门针对该组(第6组和第7组是禁用和未经证实的帐户):

Message::with(['from' …
Run Code Online (Sandbox Code Playgroud)

php mysql laravel eloquent

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

jScrollPane在元素拖动时滚动

我试图通过突出显示文本并向下拖动来滚动.现在,正如您可能已经知道的那样,这是标准overflow: auto元素的标准默认行为,但是我试图通过Kelvin Luck的jQuery jScrollPane提供一些花哨的滚动条.

我在这里创造了一个小提琴:DEMO

基本上你可以看到,突出显示和滚动工作在顶部框(默认overflow: auto框),但在第二个它没有,并且,复合事项,一旦你到达底部它改变您的选择!

所以,我的问题是这些(这些):有没有办法解决这个问题?如果是这样,怎么样?

UPDATE

我一直在研究这个问题并且已经找到了一个小问题 setTimeout()

然而,它没有按预期工作,如果有人愿意帮助我把它分成一个新的小提琴:jsFiddle

代码本身是:

pane = $('#scrolldiv2');
pane.jScrollPane({animateEase: 'linear'});
api = pane.data('jsp');

$('#scrolldiv2').on('mousedown', function() {
    $(this).off().on('mousemove', function(e) {
        rel = $(this).relativePosition();
        py = e.pageY - rel.y;
        $t = $(this);
        if (py >= $(this).height() - 20) {
            scroll = setTimeout(scrollBy, 400, 20);
        }
        else if (py < 20) {
            scroll = setTimeout(scrollBy, 400, -20);
        }
        else {
            clearTimeout(scroll);
        }
    })
}).on('mouseup', function() {
    $(this).off('mousemove'); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery highlighting jscrollpane jquery-jscrollpane

5
推荐指数
1
解决办法
1899
查看次数

Laravel Eloquent为模型关系设置默认值?

我有两个型号:

class Product extends Eloquent {

    ...

    public function defaultPhoto()
    {
        return $this->belongsTo('Photo');
    }

    public function photos()
    {
        return $this->hasMany('Photo');
    }
}

class Photo extends Eloquent {

    ...

    public function getThumbAttribute() {
        return 'products/' . $this->uri . '/thumb.jpg';
    }

    public function getFullAttribute() {
        return 'products/' . $this->uri . '/full.jpg';
    }

    ...

}
Run Code Online (Sandbox Code Playgroud)

这工作正常,我可以调用$product->defaultPhoto->thumb$product->defaultPhoto->full获取相关图像的路径,并使用所有照片$product->photos并循环遍历值.

当产品没有照片时出现问题,我似乎无法找到为这种情况设置默认值的方法.

我尝试过这样的事情

public function photos() 
{
    $photos = $this->hasMany('Photo');
    if ($photos->count() === 0) {
        $p = new Photo;
        $p->url = 'default'; …
Run Code Online (Sandbox Code Playgroud)

php laravel eloquent laravel-4

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

使用'headers'属性遍历带有JavaScript/jQuery的HTML表

可以说我有下表:

<table>
  <thead>
    <tr>
     <th id="th_00">&nbsp;</th>
     <th id="th_01">TH 01</th>
     <th id="th_02">TH 02</th>
     <th id="th_03">TH 03</th>
     <th id="th_04">TH 04</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th id="th_10">TH 10</th>
      <td headers="th_01 th_10">DATA 11</td>
      <td headers="th_02 th_10">DATA 12</td>
      <td headers="th_03 th_10">DATA 13</td>
      <td headers="th_04 th_10">DATA 14</td>
    </tr>
    <tr>
      <th id="th_20">TH 20</th>
      <td headers="th_01 th_20">DATA 21</td>
      <td headers="th_02 th_20">DATA 22</td>
      <td headers="th_03 th_20">DATA 23</td>
      <td headers="th_04 th_20">DATA 24</td>
    </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

是否有使用JavaScript或jQuery来找到使用数据的特定细胞的任何原生方式headers属性和th标签id,否则我就必须建立自己的功能?

我目前正在使用regular expressionsjQuery('td', 'table tbody').each()循环来检索我需要使用的特定单元格,虽然这不太理想,因为它单独循环遍历每个单元格.

javascript jquery html-table

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