簡體   English   中英

余燼中的空參數變量

[英]empty params variable in ember

因此,我已經設置了路由器和一些路由,這在大多數情況下都有效。 當我加載#/ contacts / 123(或其他)時,ContactIndexRoute返回一個空的params對象。 我敢肯定這是相對簡單的,但是我不知道為什么。 有人可以指出我正確的方向嗎? 謝謝。

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

僅將參數傳遞到定義該段的路由。 這意味着,如果您在資源上定義一個段,則該段僅存在於資源上,而不存在於其路由上。 如果它是在資源下的路由上定義的,則僅存在於該路由上。

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

暫無
暫無

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

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