余烬中的空参数变量 [英] empty params variable in ember

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

问题描述

所以我已经设置了一个路由器和一些路由,这在大多数情况下都有效.当我加载 #/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 只传递给定义 slug 的路由.意思是如果你在资源上定义了一个 slug,它只存在于资源上,而不是它的路由上.如果它是在资源下的路由上定义的,则它只存在于该路由上.

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);
    }
});

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

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