留言板

Create Dynimically attributes for custom Node.

Josimar Damian,修改在8 年前。

Create Dynimically attributes for custom Node.

New Member 帖子: 3 加入日期: 15-8-26 最近的帖子
Hi there!

I'm trying to create attributes dynamically for a custom node, using a bootstrap modal. When the user click on the node previously created, the modal will appear before the configuration has been read. In that modal the user specifies how many attributes will be introduced in the node, something like this:

  var model1 = null;
					    Y.DiagramNodeCustom = Y.Component.create({
					        NAME: 'diagram-node',

					        ATTRS: {
					            type: {
					                value: 'endpoint'
					            },
					            cst: {
					                validator: Y.Lang.isString,
					                value: 'DELETE'
					            }
					        },

					        EXTENDS: Y.DiagramNodeTask,
					        
					        
					        prototype: {
					        	
					            getPropertyModel: function () {
					            	
					            	var instance = this;
					            	var modulesValue = null;
					            	var endpointModules = null;
					            	
							        $('.modulesNumber').on('click',function(){
							        	
										modulesValue = this.innerText;
										
										$('#util').modal('toggle');
										
										$('div.modal-backdrop').remove();
										
										var modulesFromEndpoint = {
												jsonFields: []
											};
										
										for (i = 0; i < modulesValue; i++) {

												modulesFromEndpoint.jsonFields.push({
											    	attributeName: 'module'+ i +'',
								                    name: 'Module attribute'
											    });
											    
											}
											
										endpointModules = modulesFromEndpoint.jsonFields[0];
						                
						                model1 = Y.DiagramNodeTask.superclass.getPropertyModel.apply(instance, arguments);
						                
						                model1.push(endpointModules);
						                
						                return model1;
									
							        });
					                
					            
					            }
					        }
					        
					    });
					    
					    Y.DiagramBuilder.types['endpoint'] = Y.DiagramNodeCustom;


However , it appears that reads the configuration first and then executes the action of the modal.

What am I missing? Is there another way to push attributes dynimically?
thumbnail
Nate Cavanaugh,修改在8 年前。

RE: Create Dynimically attributes for custom Node.

Junior Member 帖子: 94 加入日期: 06-11-27 最近的帖子
Hi there,
The biggest issue I can see off the top of my head is that getPropertyModel should be returning an object, but you're returning an object from the click handler.

So the problem will look something like this:

getPropertyModel is called
a click listener is attached, which the user will probably do after this method has returned
getPropertyModel returns undefined
the user clicks and the return value is returned to the click listener, so it doesn't go anywhere.

The core issue is that you are trying to return data that's determined asynchronously (the user interaction) to a method that's expecting a synchronous return.

Off the top of my head, I'm not sure what would be the best way to accomplish what you're trying to, short of creating a new node and supplying that data on interaction, but hopefully that clears up where the issue is happening.