空白params变量在ember [英] empty params variable in ember

查看:87
本文介绍了空白params变量在ember的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我设置了一个路由器和一些路由,这在很大程度上起作用。当我加载#/ contacts / 123(或任何),ContactIndexRoute返回一个空的params对象。我相信这个比较简单,但是我不清楚为什么。有人可以指向正确的方向吗?谢谢。

So I've set up a router and some routes, and this works for the most part. when I load #/contacts/123 (or whatever) the ContactIndexRoute returns an empty params object. I'm sure this is relatively simple, but I cannot figure out why. Can someone point me in the right direction? Thanks.

CallMonitor.Router.map(function(){
    this.resource('contacts', function(){
        this.resource('contact', {path: '/:contact_id'}, function(){

        })
    });
});

CallMonitor.ContactsRoute = Ember.Route.extend({
    model: function(){
        return  this.store.find('contact');
    },
    setupController: function(controller, contacts) {
        var socket = CallMonitor.Socket;
        controller.set('socket', socket);
        controller.set('contact', contacts);
    },
    renderTemplate: function(){
        this._super(this, arguments);
        this.render('contacts', {
            into: 'application',
            outlet: 'contacts',
            controller: 'contacts'
        });
    }
});

CallMonitor.ContactIndexRoute = Ember.Route.extend({
    model: function(params){
        return  this.store.find('contact', params.contact_id);
    },
    renderTemplate: function(){
        this._super(this, arguments);
        this.render('contact', {
            outlet: 'points',
            into: 'contacts',
            controller: 'contactsIndex'
        })
    },
    setupController: function(controller, contact) {
        controller.set('contact', contact);
    }
});

CallMonitor.ContactsController = Ember.ArrayController.extend({
    actions: {
        getPoints: function(data){
            this.transitionToRoute('contact', data.id);
            console.log('the data is' + data );
        }
    },

    socketDidChange: function(){
        var socket = this.get('socket'),
            self = this;
        if(socket)
        {
            socket.on('call', function (data) {
                if(data.contactPointId){

                }
                else if (data.contactId)
                {
                    var contactToUpdate = self.contact.filter(function(item) {
                        return item.id == data.contactId;
                    });
                    if(contactToUpdate.length)
                    {
                        contactToUpdate[0].reload();
                    }
                    else
                    {
                        // reload all the contacts
                        var contactPromise = self.contact.store.find('contact');
                        contactPromise.then(function(data){
                            self.set('contact', data);
                        }, undefined);
                    }
                }
            });
        }
    }.observes('socket')
});


推荐答案

参数只传递给定义插件的路由。这意味着如果您在资源上定义了一个资源,它只存在于资源上,而不是其路由。如果它在一个资源下的路由上定义,它只能存在于该路由上。

Params are only passed to route which defines the slug. Meaning if you define a slug on the resource it only exists on the resource, and not its routes. If it's defined on a route under a resource it only lives on that route.

CallMonitor.ContactRoute = Ember.Route.extend({
    model: function(params){
        return  this.store.find('contact', params.contact_id);
    },
    renderTemplate: function(){
        this._super(this, arguments);
        this.render('contact', {
            outlet: 'points',
            into: 'contacts',
            controller: 'contactsIndex'
        })
    },
    setupController: function(controller, contact) {
        controller.set('contact', contact);
    }
});

这篇关于空白params变量在ember的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆