我有一个问题。我试图创建一个组件但是ember不会使用我自己的组件类。
// ------- main
require( ["handlebars", "ember"], function() {
app = Ember.Application.create( {
LOG_ACTIVE_GENERATION: true,
LOG_TRANSITIONS_INTERNAL: true,
LOG_VIEW_LOOKUPS: true,
LOG_BINDINGS: true,
LOG_TRANSITIONS: true
});
require(["js/components/rsa-key.js"], function() {
app.Router.map( function() {
this.resource('application', { path: "/" });
});
});
});
<script type="text/x-handlebars" data-template-name="application">
<h1>Title: {{title}}</h1>
{{rsa-key}}
</script>
// ---------- rsa-key-component
<script type="text/x-handlebars" id="components/rsa-key">
<div class="controls-row">
//.....
<label for="storageLoadKey" class="col-lg-2 control-label" {{ action "toggle" }} >Local storage: </label>
//.....
</div>
</script>
// ---------- rsa-key.js
define([], function( ) {
app.RsaKeyComponent = Ember.Component.extend({
tagName: "nav",
actions: {
toggle: function() {
alert("toggle");
},
localSave: function() {
alert("save");
}
}
});
});
奇怪的是,如果我删除“require(”rsa-key.js“)”并将其替换为内容,它就像一个魅力。
所以问题是,如果我通过require js加载它,为什么它会起作用?