【发布时间】:2014-05-15 15:48:25
【问题描述】:
我希望在转换到新路由时触发一个 Action 事件 (on="")。
我已经看到了 Action 事件处理程序列表,我能找到的最接近的是将操作附加到页面上最大的 HTML 元素并使用“Mousemove”触发它。这是一个非常有缺陷的方法去做。
所以只是把它画出来。
<div {{action 'displayEitherHtml1or2'}} class="largestDOMelement">
{{#if showHtml1}}
// html 1 inside
{{/if}}
{{#if showHtml2}}
// html 2 inside
{{/if}}
</div>
'/objects' 是一个对象列表,单击一个会导致 'object/somenumber'。当我进入“object/somenumber”页面时,该操作应该会自动触发。
更新:我已经从上一次更新中获取了内容并将它们转储到我的 DocRoute 中,但是当我通过 {{#link-to 'doc' this.docID}} { {docTitle}}{{/link-to}}
VpcYeoman.DocRoute = Ember.Route.extend(VpcYeoman.Authenticated,{
toggleLetterSwitch: false,
togglePermitSwitch: false,
activate: function () {
var docTemplateID = this.get('docTemplateID');
if ( docTemplateID == 2) {
this.set('toggleLetterSwitch', true);
this.set('togglePermitSwitch', false);
console.log('docTemplateID equals 2');
} else {
this.set('toggleLetterSwitch', false);
this.set('togglePermitSwitch', true);
}
}
});
更新 DOS:在 DocsController 中将 setDocID 设置为 1。这就是全部内容。
VpcYeoman.DocsController = Ember.ArrayController.extend({
tempDocId: 1,
actions: {
addDoc: function (params) {
var docTitle = this.get('docTitle');
var docTemplateID = 1;
var docTemplateID = this.get('tempDocId');
console.log(this.get('tempDocId'));
var store = this.store;
var current_object = this;
var doc = current_object.store.createRecord('doc', {
docTitle:docTitle,
docTemplateID:docTemplateID
});
doc.save();
return true;
},
setDocId: function (param) {
this.set('tempDocId', param);
console.log(this.get('tempDocId'))
},
}
});
【问题讨论】:
-
如果你在这里查看github.com/emberjs/ember.js/blob/master/packages_es6/… 有一个“激活”钩子,你可以在你的路由中覆盖它,当一个路由被激活时它会被触发。您可以在“beforeModel”、“afterModel”等路线中使用许多钩子。在该文件中,您可以找到所有这些钩子。希望对您有所帮助。
-
这很有帮助,pjmorse 关于“主动钩子”的建议也很有帮助。
标签: javascript events ember.js action