簡體   English   中英

從JavaScript轉換Ember.js應用程序

[英]Transition an Ember.js application from JavaScript

如何從不屬於RouteController的JavaScript函數中轉換Ember.js應用程序? 我可以直接使用Ember.Application實例調用route.transitionTo()controller.transitionToRoute()之類的Ember.Application嗎?

我要做的是將amMap集成到Ember.js應用程序中,這樣當單擊地圖上的某個區域時,應用程序將轉換為適當的狀態。

這是jsFiddle的一個例子 從列表中選擇大陸時,將在地圖上選擇該大陸。 我希望反轉也發生,我應該在以下監聽器中做什么:

map.addListener("homeButtonClicked", function () {
    // how can I transition to index from here?
    // similar to this.transitionTo("index") from a route or
    // this.transitionToRoute("index") from a controller
    alert("Transition to index");
});
map.addListener("clickMapObject", function (e) {
    // how can I transition to continent from here?
    // similar to this.transitionTo("continent", id) from a route or
    // this.transitionToRoute("continent", id) from a controller
    alert("Transition to continent: " + e.mapObject.id);
});

嗯,但是為什么要在全局功能中做到這一點,你可以享受更多的樂趣“ember way”:)

最好將map div移動到模板中並創建“IndexView”並在didInsertElement()方法中為地圖視圖添加事件處理程序。 這是一個有效的emberjsbin: http ://emberjs.jsbin.com/EsAkAVE/1/edit

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM