小编ben*_*phw的帖子

wysihtml5覆盖链接对话行为

我希望能够以任意的文本添加为使用链接的HREF wysihtml5.例如:我想生成这个<a href="[~55~]">link</a>

我已经弄清楚如何做到这一点 - 这是我正在做的一个简化的例子:

editor = new wysihtml5.Editor("text_area_content", {toolbar: "wysihtml5-toolbar"})  
editor.composer.commands.exec("createLink", { href: "[~"+55+"~]" })
Run Code Online (Sandbox Code Playgroud)

我现在的问题是,在创建链接后,当在编辑器中选择此链接时,对话框将链接显示为"http:// current_url/[~55~]".我希望它只显示"[~55~]".

我试图将一个新事件绑定到编辑器中的链接,但我无法弄清楚如何做到这一点(因为它们在iframe中).

如何在不显示当前网址的情况下获取wysihtml5链接对话框以显示链接地址?

javascript wysihtml5

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

按关联属性订购模型

我有一个Event模型,它有很多EventDates.

EventDate有一个start_time属性,Event有一个next_occurrence方法,用最近的方法查找属于它的EventDate start_time.

我想找到排序的前5个事件next_occurrence(最快的第一个).

我想我可以用这样的东西来实现这个目标:

Event.joins(:event_dates).order('event_dates.start_time').limit(5)
Run Code Online (Sandbox Code Playgroud)

但这不对 - 如果我收集next_occurrence日期,它们就会失灵.

我怎么能查询这个以返回排序的事件next_occurrence

activerecord ruby-on-rails

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

如何递归调用promise函数

我正在尝试使用 javascript Promise 递归调用异步函数,但尚未找到有效的模式。

这就是我想象的工作:

var doAsyncThing = function(lastId){
  new Promise(function(resolve, reject){
    // async request with lastId
    return resolve(response)
  }
}

var recursivelyDoAsyncThing = function(lastId){
  doAsyncThing(lastId).then(function(response){
    return new Promise(function(resolve, reject){
      //do something with response
      if(response.hasMore){
        //get newlastId
        return resolve(recursivelyDoAsyncThing(newLastId));
      }else{
        resolve();
      }
    });
  });
}

recursivelyDoAsyncThing().then( function(){
  console.log('done');
});
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?我误解了什么?

有没有更好的模式来解决这个问题?

javascript recursion promise

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