Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access controller property from function? #12

Open
ghost opened this issue Jul 28, 2015 · 1 comment
Open

How to access controller property from function? #12

ghost opened this issue Jul 28, 2015 · 1 comment
Assignees

Comments

@ghost
Copy link

ghost commented Jul 28, 2015

in a component I call a web service and save the results in a controller property.

On the didInsertElement event I grab a div (Ember.$.('#someDiv')) and initialize the bootstrap fullCalendar widget. Part of that is a handle to a function that fullCalendar calls to get event data for rendering.

In my component I have it defined like this:

import Ember from 'ember';
import moment from 'moment';
const {
    on
} = Ember;

var calData = {};
var rcId = {};

export default Ember.Component.extend({
    calEvents: function(start, end, timezone, callback) {
        // var scheduleData = this.get('scheduleData');
        var scheduleData = calData;
        ...a whole bunch of logic specific to finding events in my data for fullCalendar to display
        callback(eventData); // calling back to fullcalendar with the events to render
    },
    initialize: on('init', function() {
        var self = this;
        rcId = this.get('rcId');
        Ember.$.ajax({
            url: '/my/big/ugly/Url',
            beforeSend: function(request) {
                request.setRequestHeader('Accept', 'application/json');
            },
            dataType: 'json',
            contentType: 'application/json'
        }).done(function(data) {
            self.set('scheduleData', data);
            calData = data;
        });
    }),
    setupFullCalendar: function() {
        this._super();
        var self = this;
        Ember.$('#fullcal').fullCalendar({
            events: self.get('calEvents'),
        });
    }.on('didInsertElement')
});

As you can see, I created two variables rcId and calData and populate them so the function can use them. This clearly is not the Ember way.

If I reference this.get('calEvents') I get an undefined on get since the context isn't the controller, but rather fullCalendar.

What is the ember way??

@taras taras changed the title how to access controller property from function How to access controller property from function? Aug 3, 2015
@taras taras assigned taras and zinyando and unassigned taras Aug 25, 2015
@taras
Copy link
Member

taras commented Aug 25, 2015

@zinyando can you please fork ember-cli-full-calendar and add the following to it

  • In Dummy app, create a route that renders the calendar with some sample data
  • Write a test that checks that this data is rendered
  • In Dummy app, create a route that renders initial data and after 2000ms injects additional data
  • Write test that shows that both initial data and new data is rendered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants