Error encountered in Ember.js: Cannot call method 'get' on object #<Object>

I am attempting to utilize a model in order to generate a dynamic route that will display the date in the URL. However, I keep encountering a typedef error and I am unable to determine which 'get' is causing the issue and why the error is being thrown. Is it related to my model or my route? How can I prevent this error when creating dynamic routes? Can anyone recommend a reliable source or book that delves into the intricacies of Ember?

    var App = Ember.Application.create({
        LOG_TRANSITIONS: true
    });

    App.Router.map(function(year, month, date) {
        this.resource('calendar');
        this.resource('about'); 
        this.resource('utcDate', {path: ':utcDate'});
    });

    App.IndexRoute = Ember.Route.extend({
        redirect: function(){
            this.transitionTo('calendar');
        }
    });

    App.CalendarRoute = Ember.Route.extend({
        model: function(){
            return App.CalendarData.create();
        },
        model: function(params, transition){
            return {utcDate: params.utcDate}
        },
        serializer: function(model){
            return {utcDate: model.get('utcDate')};
        },
        serializer: function(model){
            return {month: model.get('Today')};
        }
    });

    // calendar controller
    App.CalendarController = Ember.Controller.extend({

//something here seems to be throwing an error that I can't troubleshoot       
      utcDate: function() {
        return this.get("model").get("utcDate");
      }.property("model"),

      days: function() {
        return this.get("model").get("days");
      }.property("model"),

      date: function() {
        return this.get("model").get("date");
      }.property("model"),

      month: function(){
        return this.get('model').get('month');
      }.property('model'),

      dow: function(){
        return this.get('model').get('dow');
      }.property('model'),

      year: function(){
        return this.get('model').get('year');
      }.property('model')
    });

    // calendar data
    App.CalendarData = Ember.Object.extend({
        today: new Date(),

        utcDate: function(){
          return this.get('today').getMonth()+1 + '/'+ this.get('today').getDate()+'/'+this.get('today').getFullYear();
        }.property('today'),

        date: function(){
          return this.get("today").getDate();
        }.property('today'),

        days: function(){
          var Mdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
          var Ndays =  Mdays[this.get('today').getMonth()];
          var days = [];
          var cDays = 0;
          for (var i = 0; i < 5; i++) {
            days[i] = [];
              for (j = 0; j <=6; j++) {
                if (cDays <= Ndays){
                  days[i][j] = cDays++;
                } else{
                  days[i][j] = " "
                }
              }
          }
          return days;
        }.property('today'),

        month: function(){
          var MonthA = ["January", "February", "March", "April", "May", "June", "July",  "August", "September", "October", "November", "December"];
          var month = MonthA [this.get('today').getMonth()];
          return month;
        }.property('today'),

        dow: function(){
          var Weekday = ["Sunday", "Monday", "Tuesday", "Wednesday",  "Thursday", "Friday", "Saturday"];
          var dow= Weekday[this.get('today').getDay()];
          return dow;
        }.property('today'),

        year: function(){
          return this.get('today').getFullYear();
        }.property('today')
    });

Answer №1

Your model hook and serialize hook are both defined multiple times in the code block below.

App.CalendarRoute = Ember.Route.extend({
    model: function(){
        return App.CalendarData.create();
    },
    model: function(params, transition){
        return {utcDate: params.utcDate}
    },
    serializer: function(model){
        return {utcDate: model.get('utcDate')};
    },
    serializer: function(model){
        return {month: model.get('Today')};
    }
});

To address this issue, select one of each hook to keep. Additionally, if an object is not an ember object, use Ember.get(object, property) instead of object.get(property).

App.CalendarRoute = Ember.Route.extend({
    model: function(){
        return App.CalendarData.create();
    },
    serializer: function(model){
        return {utcDate: Em.get(model,'utcDate')};
    },
});

Check out the link for more information:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to retrieve the HttpsError status from a Firebase function?

Within my firebase function, I deliberately throw an error with a specific status and message using the following code: throw new functions.https.HttpsError('permission-denied', 'Token does not match'); When I receive the server respo ...

Retrieving information from Firebase using React

Is there a way to retrieve data from Firestore? import firebase from 'firebase/compat/app'; import 'firebase/compat/auth'; import 'firebase/compat/firestore'; const firebaseConfig = { apiKey: "AIzaSyCNBAxjeKNoAPPjBV0 ...

Utilizing custom form fields with JavaScript in Symfony2

Here is my form field template: {% block test_question_widget %} {% spaceless %} <div {{ block('widget_container_attributes') }}> {% set type = type|default('hidden') %} <input type="{{ typ ...

Differences between an AngularJS function() and a factory function() when used in a

When it comes to Angular, I've come across directives being written in two different ways: .directive('example', function () { // Implementation }); .directive('example', function factory() { // Implementation }) Can you ...

Is it possible to utilize a JS script generated within the body or head of an HTML file directly within CSS code?

As a beginner in webpage development, I have a query regarding the technical aspect. Is it possible to utilize variables from a JavaScript function, which is placed either in the head or body of an HTML file, directly in CSS code to make modifications such ...

What are the steps to utilize PageObject in a dynamically created tab during a test execution?

When attempting to use my pageObjects in a newly opened tab during the test run, the test mistakenly interacts with the base page instead of the intended one. While working with a newly opened tab is successful when using const = [newPage], like in newPage ...

The getServerSideProps function is failing to execute

This code snippet provides the implementation of my App Container: import { useEffect } from "react" import axios from 'axios' import { useSelector, useDispatch } from "react-redux" import { setUserState } from '../slices ...

Issue with JQuery autocomplete

I am encountering an issue with the JQuery Autocomplete plugin where it is not providing autocomplete suggestions when I enter text. Any thoughts on why this might not be working for my code? The basic example works fine, but mine does not seem to functio ...

Contrasting the lib and es directories

I am seeking clarity on my understanding. I am currently working with a npm package called reactstrap, which is located in the node_modules folder. Within this package, there are 4 folders: dist es lib src I understand that the src folder contains the s ...

Preserve the content in the text box corresponding to the selected radio button

In my form, there are multiple radio buttons, each with an associated text box value. Users can only select one radio button at a time and submit the form. However, sometimes users will enter data in a textbox for one radio button, then switch to another o ...

What is the typical approach of JavaScript frameworks towards the 304 not-modified response?

Wondering about the inner workings of Jquery and web development in general. When a JavaScript file is requested and the server sends a 304 not-modified response, how does a framework handle it: Does it load the JS file from cache and run it? Or does it ...

Improving search engine optimization by creating efficient links with JavaScript and PHP

I'm facing a challenge when it comes to creating blog post links. My goal is to have: website.com/blog/title-name (where the title is a string retrieved from the database) instead of: website.com/views/post.php?title=title-name Here are some key code ...

The functionality of displaying an animated gif will not work when submitting a CakePHP ajax form before or after completion

I have exhaustively tested all possible scenarios using prototype, but I am unable to get my busy indicator to show no matter what I do. Despite cross-browser testing, I've had no luck. <?php echo $ajax->submit('Submit', array(' ...

Error with JSON data from the Twitch TV API

I am having trouble with the Twitch API. When a streamer is live, I work with the "Stream" property, but if they are not streaming, I need to refer to another link. I use the getJSON function to fetch the necessary API link and work with it. However, my lo ...

Manipulating arrays in JavaScript through HTML processing

I'm encountering an issue while trying to send an array to a JavaScript function. Here's what I have so far: Within the controller: @data = [{date: '2014-08-17'}, {date: '2014-08-20'}].to_json In the view: <%= content_t ...

Refresh object attributes with newly retrieved data from MongoDB

I've been attempting to update object properties with new data retrieved from MongoDB. However, the following code isn't working as expected and I can't figure out why. Can anyone provide some assistance? var UserDB = require('../mode ...

Records are being loaded into the table, but the browser is unresponsive

After making an ajax call, I am receiving over 1000 tr elements for the tbody of a table. However, when I try to load this data into the tbody of the table, Loading the records into the tbody of the table becomes a problem. $('#loadingRecords') ...

Angular does not always interpret the value returned from a Promise.all call

One of the challenges I'm facing is related to the structure of my controller: controller.things = ['a', 'b', 'c']; controller.loading = true; controller.responses = []; controller.handlePromises = function(){ var pr ...

Enhancing user experience through real-time content updates using AngularJS directive, factory, and the power of ng-repeat

I have been putting in countless hours trying to create a widget that changes its content dynamically when I click a specific button, but so far, I haven't had any luck. Using Angular factory, I have stored all the necessary data. My goal is to trigg ...

Activate the submission button on AngularJS once a correctly formatted email is provided

Currently working on an AngularJS demo to better understand its functionalities. The next task on my list is to enable the submit button only when a valid email address is entered. I'm seeking guidance on how to approach this and what concepts I need ...