2013-06-01 111 views
1

我正在嘗試將Dropbox選擇器整合到我的餘燼應用中。這是由dropbox生成的片段。使用餘燼添加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> 

這是我試圖在燼中實現它。

包含在應用程序佈局文件中的<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"}}/> 

這是行不通的。我的問題是我們如何添加自定義事件監聽器到html 元素在燼?

+0

餘燼只有意識到內部發生的事件e' body'因爲這是ember掛鉤來做事件委託的地方,你的dropbox代碼片段在body標籤裏面嗎? – intuitivepixel

回答

1

怎麼樣使用Dropbox的選配直接通過JavaScript(中途下的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)