javascript – Ember.js弃用了registerImplementation,支持App.initializer

前端之家收集整理的这篇文章主要介绍了javascript – Ember.js弃用了registerImplementation,支持App.initializer前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用HashLocation的扩展来为Ember.js实现一个hashbang url类型.

这是代码片段:

(function() {

var get = Ember.get,set = Ember.set;

Ember.Location.registerImplementation('hashbang',Ember.HashLocation.extend({ 

    getURL: function() {
        return get(this,'location').hash.substr(2);
    },setURL: function(path) {
        get(this,'location').hash = "!"+path;
        set(this,'lastSetURL',"!"+path);
    },onUpdateURL: function(callback) {
        var self = this;
        var guid = Ember.guidFor(this);

            Ember.$(window).bind('hashchange.ember-location-'+guid,function() {
                Ember.run(function() {
                    var path = location.hash.substr(2);
                    if (get(self,'lastSetURL') === path) { return; }

                    set(self,null);

                    callback(location.hash.substr(2));
                });
            });
        },formatURL: function(url) {
            return '#!'+url;
        }

    }));

})();

我通过重新打开路由器来使用它:

App.Router.reopen({
    location: 'hashbang'
});

但是,在运行应用程序时,我正在进行以下弃用:

DEPRECATION: Using the Ember.Location.registerImplementation is no longer supported. Register your custom location implementation with the container instead.

我找不到任何有关如何执行此操作的信息.有没有人对我必须做的事情有任何实施片段?

解决方法

根据弃用消息.改用容器.
(function() {

var get = Ember.get,set = Ember.set;

var hashbangLocation = Ember.HashLocation.extend({ 

    getURL: function() {
        return get(this,formatURL: function(url) {
            return '#!'+url;
        }

    });

App.register('location:hashbang',hashbangLocation);

})();

像往常一样重新打开它

App.Router.reopen({
    location: 'hashbang'
});
原文链接:https://www.f2er.com/js/150330.html

猜你在找的JavaScript相关文章