我刚刚开始使用Vue.js,并发现自己不断转向jQuery来帮助某些情况.最近,我试图"触发"(或模仿)某个事件,例如点击或模糊事件,但未成功.
我知道在jQuery中你可以做到以下几点:
$('#my-selector').trigger('click');
Run Code Online (Sandbox Code Playgroud)
但是如何使用Vue.js实现这一目标呢?我想尽可能地避免使用jQuery.
以下面的例子为例:
<div id="my-scope">
<button type="button" v-on="click: myClickEvent">Click Me!</button>
</div>
<script>
new Vue({
el: "#my-scope",
data: {
foo: "Hello World"
},
methods: {
myClickEvent: function(e) {
console.log(e.targetVM);
alert(this.foo);
},
anotherRandomFunciton: function() {
this.myClickEvent();
}
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
如果我要调用anotherRandomFunciton,我希望它模拟(或触发)上面的click事件.但是,我尝试这个事件(或上例中的e)永远不会传递给函数.
Vue.js有实现这个目标的方法吗?
我很难概念化一个递归函数,用于将回复附加到评论、回复回复、回复回复等。
这是我的评论表:

这应该渲染时是这个样子:

就目前而言,我可以呈现与 article_id 关联的每个评论(NOT NULL当然不包括那些评论):
$comments = $commentClass->fetch_article_comments($article_id);
foreach($comments as $comment) {
$comment_id = $comment['comment_id'];
$member_id = $comment['member_id'];
$comment_text = $comment['comment_text'];
$comment_timestamp = timeAgo($comment['comment_timestamp']); //get time ago
//render comment using above variables
}
Run Code Online (Sandbox Code Playgroud)
现在我假设我需要在上述foreach语句的末尾添加一个递归函数,但是我还没有想出任何远程成功的方法来附加评论回复和对每个回复的回复。
任何人都可以帮助我实现这一目标,或者为我指明正确的方向。我对递归函数并不完全熟悉。我已经对互联网和 stackoverflow 进行了一些扫描,寻找有帮助的东西,但还没有找到任何有用的东西。
我确实遇到过这篇推荐使用分层数据库系统的帖子,但我想我更愿意为此使用 php 递归函数。
谢谢。
编辑
通过使用以下答案,我只返回结果第一个评论,然后无限期地迭代并显示该评论。我想不通为什么?
我的PHP:
function display_comments($article_id, $parent_id=0, $level=0) {
global $comment;
global $member;
global $signed_in;
global $username;
$comments = $comment->fetch_article_comments($article_id, $parent_id);
foreach($comments as $data) {
$comment_id = $data['comment_id']; …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习 Laravel,想知道是否可以创建一个 Route::resource 来允许我使用 RESTful 方法访问以下 URL:
我希望 URL 看起来像这样:
http://example.com/articles/2014/09/22/this-is-the-article-title
Run Code Online (Sandbox Code Playgroud)
我想使用以下方法从我的 ArticlesController 访问它:
//GET articles/{year}/{month}/{day}/{title}
public function show($year, $month, $day, $title) {
$article = //find article in DB
return View::make('articles.show')->with('article', $article);
}
Run Code Online (Sandbox Code Playgroud)
根据我到目前为止收集到的信息,这可以通过在 paths.php 文件中执行如下操作来完成:
Route::resource('year.month.day.articles', 'ArticlesController');
Run Code Online (Sandbox Code Playgroud)
但这对我来说看起来不太正确。
有没有人有什么建议?
我有许多复选框,我想检查它们是被选中 (1) 还是未选中 (0)。我想将结果放在一个数组中,以便我可以将它们发送到服务器以保存在表中。我试过下面的代码:
<input class="publish" id="chkBox1" type="checkbox" checked>
<input class="publish" id="chkBox2" type="checkbox" checked>
<input class="publish" id="chkBox3" type="checkbox" checked>
<input class="publish" id="chkBox4" type="checkbox" checked>
<input class="publish" id="chkBox5" type="checkbox" checked>
<script>
$('#save-btn').click(function(evt){
evt.preventDefault();
var numberOfChBox = $('.publish').length;
var checkArray = new Array();
for(i = 1; i <= numberOfChBox; i++) {
if($('#chkBox' + i).is(':checked')) {
checkArray[i] = 1;
} else {
checkArray[i] = 0;
}
}
alert(checkArray);
});
</script>
Run Code Online (Sandbox Code Playgroud)
但警报输出:
,1,0,1,0,1,1
Run Code Online (Sandbox Code Playgroud)
除了 undefined 中的第一个索引外,这些值都是正确的。总共只有 5 个复选框,但数组有 6 个索引长。为什么是这样?
我有〜150个文件需要从中删除jQuery导入,因为我们有Webpack自动导入它。
如何在vscode中找到并替换呢?我想从每个文件中删除一行,并使其余代码向上移动一行。我有下面的正则表达式,但是,我不确定我需要在replace字段中删除该行。
我的ajax请求有点困难.似乎$ .post方法根本不起作用,没有发送请求.在firebug中也没有任何东西出现.
我可以让这个工作:
$('.comment-remove').click(function (evt) {
evt.preventDefault();
var sure = confirm('Are you sure your want to remove your comment from this thread?');
if(sure) {
var comment_id = $(this).attr('id');
alert(member_id);
}
});
Run Code Online (Sandbox Code Playgroud)
但不是这个:
$('.comment-remove').click(function (evt) {
evt.preventDefault();
var sure = confirm('Are you sure your want to remove your comment from this thread?');
if(sure) {
var comment_id = $(this).attr('id');
$.post('comment.php', { comment_id: comment_id }, function(data) {
if (data === 'success') {
alert(data);
} else {
alert('Unable to remove comment at this time.'); …Run Code Online (Sandbox Code Playgroud)