小编Lov*_*ess的帖子

使用Laravel中的Eloquent使用Foreach循环反转数组元素

我有一个得分表,有不同的评级,字符串和单选按钮.

现在我想循环这些.通常我会像这样解决它:

 <table>
    <tr>
        <th>ID</th>
        <th>Type</th>
        <th>Comment</th>
    </tr>
    @foreach($scores as $score)

    <tr>
        <td>{{$score->id}}</td>
        <td>{{$score->ratingradio}}</td>
        <td>{{$score->ratingtext}}</td>
    </tr>

    @endforeach
</table>
Run Code Online (Sandbox Code Playgroud)

但是我不仅希望颠倒顺序,而且还希望对数组进行切片,以便它只输出数组的最后20个元素.

我试图在我的控制器中解决这个问题:

$scores = Score::where('unit_id', $id)->where('created_at', '>', Carbon::now()->subDays(3))->get();


// Save all ratingtexts in an array
$comments = $scores->lists('ratingtext');
$commenttype = $scores->lists('ratingradio');
// Get the last 20 Elements of the Array
$comments = array_slice($comments, -20, 20, true);
// Reverse the array, to have the latest element first displayed
$comments = array_reverse($comments, true);
Run Code Online (Sandbox Code Playgroud)

然后循环遍历$ comments.但我不仅要显示评论,我还希望能够显示有关此元素的所有信息.所以最好像上面的方法一样雄辩,我输出$ score-> ratingtext,$ score-> ratingradio,$ score-id,以及我想要的任何东西.

我试过用

 @foreach(array_reverse($scores) as $score) …
Run Code Online (Sandbox Code Playgroud)

php arrays laravel eloquent

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

VueJs:在v-repeat指令中使用v-el指令专注于输入

我使用v-repeat指令显示一个列表.

http://jsfiddle.net/ftc9ev7p/1/

请注意v-el指令的动态创建的参数,该参数由

v-el="inputField{{task.id}}" 
Run Code Online (Sandbox Code Playgroud)

或者

v-el="{{'inputField' + task.id }}"
Run Code Online (Sandbox Code Playgroud)

仍然没有得到认可,因为我得到:

Uncaught TypeError: Cannot read property 'focus' of undefined
Run Code Online (Sandbox Code Playgroud)

我想单击编辑按钮并关注相应的输入字段.

当我动态添加css类时,类似的语法有效.只需取消注释.focus()并单击"编辑".

		new Vue({
		  el: '#tasks',

		  data: {
		    "tasks": [{
		      "id": 25,
		      "body": "Slack Noooo Yes",
		      "completed": true,
		      "created_at": "2015-08-05 17:00:26",
		      "updated_at": "2015-08-05 17:00:26"
		    }, {
		      "id": 27,
		      "body": "And",
		      "completed": false,
		      "created_at": "2015-08-05 17:22:14",
		      "updated_at": "2015-08-05 17:22:14"
		    }, {
		      "id": 28,
		      "body": "Happiness",
		      "completed": false,
		      "created_at": "2015-08-05 17:22:16",
		      "updated_at": "2015-08-05 17:22:16"
		    }, {
		      "id": 29,
		      "body": "Love", …
Run Code Online (Sandbox Code Playgroud)

html javascript list laravel vue.js

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

Javascript:在另一个方法中调用一个方法

我有一个简单的应用程序,它触发一个布尔值并将任务设置为完成:

但我希望能够使用"全部完成"按钮并完成每项任务.这在这里工作正常:

  completeAll: function() {
    this.tasks.forEach(function(task) {
      task.completed = true;
    });
  },
Run Code Online (Sandbox Code Playgroud)

http://codepen.io/anon/pen/avzMYr

但是我不想直接设置它,而是想使用这样调用的方法,因为我有很多其他需要分离的代码.

  completeTask: function(task) {
    task.completed = true;
  },

  completeAll: function() {
    this.tasks.forEach(function(task) {
      this.completeTask(task);
    });
  },
Run Code Online (Sandbox Code Playgroud)

但这不起作用,请看这里:

http://codepen.io/anon/pen/EVaMLJ

知道如何在completeAll方法中调用"completeTask(task)"方法吗?

javascript function vue.js

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

如何在移动菜单上使用twitter bootstrap时删除出现的水平滚动条

请帮帮我.我设置了一个Twitter引导程序菜单,但是当我使用移动版时,会出现一个水平滚动条:

http://i.imgur.com/JRWRg9D.jpg

我能够在jsfiddle上重现它:

http://jsfiddle.net/mXLSk/

我正在使用它来设置移动版本的样式,但必须隐藏另一种让滚动条出现的样式.

 @media (max-width: 767px) { 
    #bs-example-navbar-collapse-1 {
        background-color: #fff;

        a {
            padding: 7px 40px;
        }
    }
 }
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

html css twitter-bootstrap

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

Polymer:我在哪里把Javascript放到Element中?

我在普通的Polymer Elements中加载Javascript时遇到问题:

这是在没有聚合物的情况下执行时完美无缺的测试代码:

 <body>
    <style>
    #content {background-color: #f2f2f2;}
    #button {padding: 10px 20px;}
    </style>

    <div id="content">
        <h1 id="title">Title</h1>

        <p>This example uses the addEventListener() method to attach a click event to the document.</p>


        <button id="button">Testbutton</button>
    </div>

    <script>
        function popup2() {
            alert("What's up brow?");
            console.log("deine mudda");
        };

        var button = document.getElementById("button");
        button.addEventListener("click", popup2, false);
    </script>
</script>

</body>
Run Code Online (Sandbox Code Playgroud)

但是我想在Polymer Elements中使用Javascript并尝试以下插入:

NR.1:脚本标签内的Javascript,在模板标签之后:

 <polymer-element name="my-element">

    <template>
        <style>
        #content {background-color: #f2f2f2;}
        #button {padding: 10px 20px;}
        </style>

        <div id="content">
            <h1 id="title">Title</h1>

            <p>This example uses the addEventListener() method to …
Run Code Online (Sandbox Code Playgroud)

javascript polymer

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

array_slice不返回最后的值

我不明白为什么它不能在我的机器上工作:

$texts = array('a', 'b', 'c', 'd', 'e', 'f', 'g');
$whatever = array_slice($texts, 0, -3, true);
dd($whatever);
Run Code Online (Sandbox Code Playgroud)

这将返回"a,b,c,d",但我希望它返回"e,f,g".

如果我写

$whatever = array_slice($texts, 0, 4, true);
Run Code Online (Sandbox Code Playgroud)

这也返回"a,b,c,d"

我想要的只是返回"e,f,g" ,手动示例似乎不适用于我的机器.

编辑:我刚看到,如果我这样做:

 $whatever = array_slice($texts, -3);
Run Code Online (Sandbox Code Playgroud)

我将得到数组的最后3个元素,但顺序错误.我希望最后一个数组是第一个.我想我需要反转阵列,还是有另一种方式?

php

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

Polymer:在自定义元素中使用 querySelector 而不是“this.$”。

编辑:刚刚找到这个链接,它以某种方式解释了它。 使用 querySelector 查找 Polymer 模板内的嵌套元素返回 null

尽管如此,我还是很高兴能回答我关于这个特定代码的问题。

/编辑

我认为一个相当直接和简单的问题:

我有一个聚合物自定义元素:

 <polymer-element name="my-test">
    <template>
        <div id="content">
            <h3 id="test">My Test</h3>
            <p id="paragraph">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi dolore consectetur, mollitia eos molestias totam ea nobis voluptatibus sed placeat, sapiente, omnis repellat dolores! Nihil nostrum blanditiis quasi beatae laborum quisquam ipsum!</p>
            <button id="button">Clicke Me!</button>
        </div>

    </template>
    <script>
    Polymer('my-test', {
        ready: function() {
            var button = this.$.button;
            button.addEventListener("click", function() {
                alert("alert");
            });
        }
    });
    </script>
</polymer-element>
Run Code Online (Sandbox Code Playgroud)

问题是,我宁愿使用

 var button …
Run Code Online (Sandbox Code Playgroud)

javascript polymer

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

Gulp Uncss打破Bootstrap Dropdown导航栏导航

我想在我的一个大css文件中使用uncss,但这样做打破了我的引导程序导航的下拉列表.

这是工作部分:http://metalotechnika.com

以下是我使用unss的部分:http://metalotechnika.horyzon.de .

您会注意到下拉菜单无效.它是使用twitter bootstrap导航栏.

我的gulpfile部分看起来像这样:

gulp.task('uncss', function() {
    return gulp.src('style.css')
        .pipe(uncss({
            html: ['uncss/uncss.html']
        }))
        .pipe(gulp.dest(''));
});
Run Code Online (Sandbox Code Playgroud)

即使我在这里选择了一个URL,它也会中断.我暂时禁用了生产站点上的缓存和css压缩,这样你就可以看看style.css中的重要区别,即获得"unss"的那个.

如何使用uncss减少我的CSS?为什么它会破坏,我该如何解决这个问题呢?

html css wordpress twitter-bootstrap uncss

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