Getting a error "Uncaught TypeError: undefined is not a function" when calling a function

Sonalkumar sute

Following is my code, somewhere I am doing something wrong while calling the function but I am not able to find it, please help me with this.

this._copyChild(final_features);

Above line of code gives me above error in the below program, see for arrow in the code

            launch: function() {
                Ext.create('Rally.ui.dialog.ChooserDialog', {
                    width: 450,
                    autoScroll: true,
                    height: 525,
                    title: 'Select to Copy',
                    pageSize: 100,
                    closable: false,
                    selectionButtonText: 'Copy',                  
                    artifactTypes: ['PortfolioItem/Feature','PortfolioItem/MMF'],
                    autoShow: true,
                    storeConfig:{
                        fetch: ['Name','PortfolioItemTypeName']
                    },
                    listeners: {
                        artifactChosen: function(selectedRecord) {
                            childrens = [];
                            this._type = selectedRecord.get('PortfolioItemTypeName');
                            this._newObj = selectedRecord;
                            this.onqModelRetrieved();
                            this.getChildrens(selectedRecord);
                        },
                        scope: this
                    },
                }); 
            },
            getChildrens: function(selectedRecord) {
                Ext.create('Rally.data.wsapi.Store', {
                    model: 'PortfolioItem/' + this._newObj.get('PortfolioItemTypeName'),
                    fetch: ['Name', 'FormattedID', 'Children'],
                    pageSize: 1,
                    autoLoad: true,
                    listeners: {
                        load: function(store, records) {
                            final_features = [];
                            Ext.Array.each(records, function(child){
                                var item = selectedRecord;
                                var childrens = item.getCollection('Children');
                                childrens.load({
                                    fetch: ['FormattedID'],
                                    callback: function(childrens, operation, success){
                                        Ext.Array.each(childrens, function(child){
                                            if (child.get('PortfolioItemTypeName') == "Feature") {
                                                final_features.push(child);
            =============>                      this._copyChild(final_features);
                                            }   
                                        }, this);   
                                    },
                                    scope: this     
                                });     
                            }, this);
                        }   
                    }
                });             
            },
            // Inner Copy functions
            _copyChild: function(final_features) {
                var that = child;
                this.innerModelRetrieved(child);
            },
manji

Inside that each function, this does not point to your outer object, but to the listeners object.

Creat a local var pointing to the outer object at the beginning of the getChildrens function and replace all scope params with it.

getChildrens: function(selectedRecord) {
    var self = this; // <-- local copy of `this` (owner of getChildrens)
    Ext.create('Rally.data.wsapi.Store', {
    ...
            Ext.Array.each(childrens, function(child){
                if (child.get('PortfolioItemTypeName') == "Feature") {
                    final_features.push(child);
                    this._copyChild(final_features);
                }   
            }, self); // <--- replace `this` with `self`

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

"Uncaught TypeError: undefined is not a function" Error message in Javascript when calling a method in an object

Trying to make a clock in JavaScript, getting an error, Uncaught TypeError: undefined is not a function

Getting an Uncaught TypeError: undefined is not a function in JSFiddle

"Uncaught TypeError: undefined is not a function" console error appearing

drupal jquery error: Uncaught TypeError: undefined is not a function

Error message "Uncaught TypeError: undefined is not a function" (DataTable)

Why is there an error, "Uncaught TypeError: undefined is not a function"?

Uncaught TypeError: undefined is not a function

Uncaught TypeError: undefined is not a function

Uncaught TypeError: undefined is not a function?

Uncaught TypeError: undefined is not a function $

`Uncaught TypeError: undefined is not a function` error trying to save data

Uncaught TypeError: undefined is not a function when using require.js

jQuery "Uncaught TypeError: undefined is not a function" when using fadeIn();

Uncaught TypeError: undefined is not a function when moved same code to another site

uncaught typeerror undefined is not a function on .empty()

Uncaught TypeError: undefined is not a function for datatables

Uncaught TypeError: undefined is not a function in RefluxJS

Uncaught TypeError: undefined is not a function:67

Another: uncaught typeerror undefined is not a function

Uncaught TypeError: undefined is not a function in datepicker

Uncaught TypeError: undefined is not a function - datatables

Uncaught TypeError: undefined is not a function - Slider

Why does JS Fiddle give me the error `Uncaught TypeError: undefined is not a function `?

Uncaught TypeError undefined is not a function anonymous function

Javascript regex .test() "Uncaught TypeError: undefined is not a function"

BigVideo.js - Uncaught TypeError: undefined is not a function

Uncaught TypeError: undefined is not a function for request() in Titanium

Ember.js: Uncaught TypeError: undefined is not a function