【问题标题】:Multiple Aviary Feather多鸟舍羽毛
【发布时间】:2014-06-06 16:43:21
【问题描述】:

我对 Aviary Feather 的集成有疑问。 在我的 javascript 中,我需要像这样使用 Feathers:

// Aviary init
var featherProductEditor = new Aviary.Feather({
  apiKey: 'myapykey',
  apiVersion: 3,
  theme: 'dark',
  tools: 'all',
  appendTo: '',
  onSave: function(imageID, newURL) {
    // Do things for featherProductEditor
    console.log('featherProductEditor');
    // Close the editor
    featherProductEditor.close();
  }
});

// Aviary init
var featherContentBlockEditor = new Aviary.Feather({
  apiKey: 'myapykey',
  apiVersion: 3,
  theme: 'light',
  tools: 'all',
  appendTo: '',
  onSave: function(imageID, newURL) {
    // Do things for featherContentBlockEditor
    console.log('featherContentBlockEditor');
    // Close the editor
    featherContentBlockEditor.close();
  }
});

那我叫这两个羽毛

featherProductEditor.launch({ ....

featherContentBlockEditor.launch({ ....

但调用的唯一“onSave*:”回调是“featherContentBlockEditor”变量的第二个

为什么?我该如何解决这个问题?

【问题讨论】:

  • 您是否尝试过是否调用onErroronReady 回调而不是onSave
  • 是的,我已经尝试过了,onError 不返回任何内容。 onReady 总是调用第二根羽毛初始化
  • 您在x.launch({ ... 中提供了什么?由于该对象是一个配置覆盖,所以很高兴知道那里有什么。

标签: javascript aviary


【解决方案1】:

对于第一个问题,为什么只调用第二个onSave

在内部,Aviary Web SDK 将羽毛配置存储在 AV.launchData 中,AVAviary 全局变量的别名。这是Aviary.Feather函数的代码sn-p:

AV.Feather = function (config) {
    ...
    AV.launchData = AV.util.extend(AV.baseConfig, config);
    ...
}

所以,这意味着featherContentBlockEditor 的配置将覆盖featherProductEditor 的配置。

您可以通过在创建每个羽毛后添加AV.launchData.onSave() 来验证这一点。

关于第二个问题,我该如何解决?

不,你不能不入侵 SDK。这就是 Aviary Web SDK 的工作原理,每页只定义一个 Aviary.Feather 实例。

【讨论】:

    【解决方案2】:

    如何解决?

    您可以使用imageID 来确定哪个 Aviary 实例产生了 onSave 事件。

      onSave: function(imageID, newURL) {
        if(imageID === 'productImg') {
          // Do things for featherFeatureEditor
          console.log('featherProductEditor');
        } else {
          // Do things for featherContentBlockEditor
          console.log('featherContentBlockEditor');
        }
        // Close the editor
        featherContentBlockEditor.close();
      }
    

    使用image:'productImg' 为您的产品图片的启动配置。

    【讨论】:

      【解决方案3】:

      在给定页面上只能有一个 Aviary 编辑器实例,但您可以通过调用来重用它:

        editor.close(true); // passing true forces an immediate close without triggering shutdown animation
        editor.launch({ image: new_id, url: new_url });
      

      【讨论】:

        猜你喜欢
        • 2016-06-01
        • 2018-08-22
        • 2012-11-11
        • 2021-06-12
        • 2019-09-21
        • 2013-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多