javascript - 使用 ember 添加 Dropbox 选择器

标签 javascript ruby-on-rails ember.js dropbox

我正在尝试将 Dropbox 选择器集成到我的ember 应用程序中。这是 dropbox 生成的代码片段。

<script type="text/javascript" src="https://www.dropbox.com/static/api/1/dropins.js" id="dropboxjs" data-app-key="XXXXXXXXXXX"></script>

<input type="dropbox-chooser" name="selected-file" id="db-chooser"/>
<script type="text/javascript">
    document.getElementById("db-chooser").addEventListener("DbxChooserSuccess",
        function(e) {
            alert("Here's the chosen file: " + e.files[0].link)
        }, false);
</script>

这就是我尝试在 ember 中实现它的方法。

包含<script type="text/javascript" src="https://www.dropbox.com/static/api/1/dropins.js" id="dropboxjs" data-app-key="XXXXXXXXXXX"></script>在应用程序布局文件中。

window.App = Ember.Application.create({
  rootElement: '#ember-app',

  customEvents: {
    DbxChooserSuccess: "DbxChooserSuccess"
  },

)};

App.TestView = Em.View.extend({
  templateName: "test_view",

  tagName: "li",

  testAction: function(e) {
    alert("DbxChooserSuccess event triggered");

  }

});

//test_view.js.hjs
<input type="dropbox-chooser" name="selected-file" id="db-chooser" {{action "testAction" on="DbxChooserSuccess" target="view"}}/>

这不起作用。我的问题是我们如何添加自定义事件监听器到 ember 中的 html 元素

最佳答案

直接通过 javascript 使用 Dropbox Chooser 怎么样(the chooser documentation 页面的中间位置)

JavaScript:

App.IndexController = Ember.ArrayController.extend({
  dropboxChooser: function() {

    Dropbox.choose({
      linkType: "direct",
      multiselect: false,
      success: function(files) {
                // Required. Called when a user selects an item in the Chooser
                alert("Here's the file link:" + files[0].link);
      },
      cancel:  function() {}
    });
  }
});

模板:

<button {{action dropboxChooser}}>Choose Dropbox File</button>

Sort of functional JSBin (no valid data-app-key)

关于javascript - 使用 ember 添加 Dropbox 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16875854/

相关文章:

ruby-on-rails - Rails 4 不完全支持 CanCan

ruby-on-rails - 未返回LinkedIn photo_urls或picture-urls::(原始)

javascript - 在 Ember.js 应用程序中,在哪里添加 jQuery 以根据浏览器大小调整 div 大小?

javascript - 识别网页中的组件使用了哪些 JS 函数和 CSS

javascript - 使用 Javascript 确定网站是公开的还是私有(private)的

javascript - Jquery:- 计算每个 tr 中 td 的数量

javascript innerhtml 不会更改源代码上的内容

ruby-on-rails - 包含助手不起作用

javascript - emberjs 中查询参数允许的值

javascript - 是否可以为 React 的类模型打开 React.js 自动绑定(bind)