Issue #724Opened January 5, 2018by kickbk0 reactions

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

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, 20180 reactions

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, 20180 reactions

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, 20180 reactions

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...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.