Can i pass params in the do Methods

Hi Team,

Can i call a method with params in it, like
this.doGoTables({id: id});

Added below the total code -
enyo.kind({
	name : 'OB.UI.Section',
	kind : 'OB.UI.ToolbarButton',
	icon : 'btn-icon',
	events : {
		onAddNewOrder : '',
		onGoTables: ''
	},
	handlers : {
		onLeftToolbarDisabled : 'disabledButton',
		ontap: "anythingTap"
	},
	disabledButton : function(inSender, inEvent) {
		this.isEnabled = !inEvent.status;
		this.setDisabled(inEvent.status);
	},
	initComponents : function() {
		this.inherited(arguments);
	},
	anythingTap : function(inSender, inEvent) {
		var id = inSender.id;
		alert(id);
		this.doGoTables({id: id});
	}
});

The method onGoTables() is present in its parent class -
enyo.kind({
	name : 'OB.OBPOSPointOfSale.UI.SectionBar',
	classes : 'span12',
	components : [ {
		tag : 'ul',
		classes : 'unstyled nav-pos row-fluid',
		name : 'toolbar'
	} ],
	handlers: {
		onGoTables: 'goTables',
	},
	initComponents : function() {
		this.inherited(arguments);
		var sectionDetail = new OB.DS.Process('org.openbravo.retail.posterminal.steward.SectionDetail');
		me = this;
		sectionDetail.exec({
		}, 
		function (data) {
			enyo.forEach(data.sections, function(section) {
				me.$.toolbar.createComponent({
					kind : 'OB.OBPOSPointOfSale.UI.TablesButton',
					button :  {
						kind : 'OB.UI.Section',
						content: section.sectionName,
						id: section.sectionId
					}
				});
			}, this);
		});
	},
	goTables: function(inResponse) {
		alert("in go tables");
		alert(inResponse.id);
		alert(inResponse);
	}
}); 

How can i access the data in params like the ID which i set passed in the params.

--
Thanks

Comments

  • You've got the right idea. Custom event handlers have the same method signature as built-in event handlers (there's really no difference between the two).
    function eventHander(inSender, inEvent) {}
    In your example, the object you passed to doXXX() will be the inEvent parameter in your handler:
    goTables: function(inSender, inEvent) {
        alert(inEvent.id);
    }
    As an aside, Enyo expects that the event payload be an object so it can be decorated by the framework and other kinds in the event chain. So, if you want to pass a primitive type (integer, boolean), you must wrap it with an object (like you did above). If you want to pass an object, be aware that if you just pass your object to doXXX, the object will be modified by the framework. To avoid this, wrap that object as well like so:
    someMethod: function() {
       // this is my custom object, perhaps it represents an entity in a database
       var data = {id:123, name:"mydata"};
       // wrapping it in another object so that object is modified
       // by the event chain and not the object above
       this.doNotify({data:data});
    }
Sign In or Register to comment.