Issue #724💬 AnsweredOpened January 5, 2018by kickbk0 reactions

This.get(...).each is not a function

快速解答by NicholasGati

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)

NicholasGatiJanuary 5, 2018

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 :)

ryandebaJanuary 7, 2018

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

kickbkJanuary 7, 2018

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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

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.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.