This.get(...).each is not a function
Just wondering, does this.get(...) return an array? If not, maybe you can try this: Not sure if that's what the issue is but I figured I'd chime in and try to help :)
Read full answer below ↓Question
Getting this.get(...).each is not a function with the latest 0.12.58 version (cdn min.js).
The line that triggers it is return this.get("classes").each(function(e){return t.push(e.get("name"))})
Answers (3)
Just wondering, does this.get(...) return an array? If not, maybe you can try this:
const c = this.get("classes");
Array.from(c).forEach(e => t.push(e.get("name")));
Not sure if that's what the issue is but I figured I'd chime in and try to help :)
Hi @kickbk,
It is unclear what this is bound to in your code...is that a reference to a component? If you could create a jsfiddle to demonstrate the error, that would be very helpful.
I've not been able to recreate the error so far. I ran this code in the demo (which also currently uses version 0.12.58) after selecting a random component and it worked without errors:
t = []; editor.getSelected().get("classes").each(function(e) { t.push(e.get("name")) })
Thanks for replying guys. I traced the issue to my custom components' Traits. What's triggering it is that I load default values for traits:
export default (editor, {
dc, opt, defaultModel, defaultView, coreMjmlModel, coreMjmlView
}) => {
const type = 'mj-my-component';
dc.addType(type, {
model: defaultModel.extend({ ...coreMjmlModel,
defaults: { ...defaultModel.prototype.defaults,
'custom-name': 'Footer',
draggable: '[data-type=mj-column]',
droppable: false,
stylable: [...],
style: {...},
traits: [
{
name: 'organization-content',
label: 'Organization Name',
default: 'TEST', // << HERE IS THE ISSUE
},{...}
],
...
As you can see my plugin extends on grapesjs-mjml.
Changing default to value gives the same error.
Is this the wrong way to load defaults to traits?
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1003
[Question/ bug]"Uncaught TypeError: t.get is not a function" on adding select-comp
on adding button "select" component { id : 'select', className : 'fa fa-mouse-pointer', command : 'select-comp', }, in button's panels gett...
Issue #1586
[Question] update Trait select option dynamically
I tried this to update trait selection. var updateTrait = function(id, name) { var typeTrait = model.get('traits').where({name: 'type'})[0]...
Issue #1337
[Question] Loading from package in TypeScript giving undefined error.
Similar to issue #902 but I can't seem to resolve with the steps taken in that discussion. I'm using the latest version of Angular, Webpack...
Issue #1520
[Bug] On this.components() Error : Uncaught TypeError: Cannot read property 'each' of undefined
Get below error for this.components() not sure if it is bug or I am doing something wrong. Uncaught TypeError: Cannot read property 'each'...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.