javascript - How to break parent function from submethod -


this question has answer here:

i have function searchkeyboardcmd binded event handler textbox. purpose check data in textbox unique. if no should break execution of handler , show alert window. if unique should data other texboxes , store in array ( code fragment line `var a=new ())

self.searchkeyboardcmd = function (data, event) {         if (event.keycode == 13) { //checking if enter pressed or other key             foo(function (result) {                 if (result == 'false') {                     alert("numer seryjny nie jest unikalny");                     return true;                 }             });              var = new eq();             a.storageid(self.storagetemp());             a.startdate(self.startdatetemp());             a.deviceserialnumber(self.test());             a.deviceid(self.devicetemp());             a.issue(self.issue())             a.issuedesc(self.issuedesc());             a.quantity(self.number());             a.project(self.project());             a.meuser(self.meuser());              self.data.push(a);             $('.datepicker').datepicker({ autoclose: true, todayhighlight: true/*, language: "pl"*/, format: 'dd/mm/yyyy' });             deviceidfield.focus();             self.test("");             return false;         }         return true;     }; 

my foo function call end method. receives true if unique. false other ways.

function foo(callback) {     $.ajax({         url: "/deviceinstance/isunique",         contenttype: "application/json; charset=utf-8",         type: "post",         datatype: "json",         data: json.stringify({ value: viewmodel.test() }),         error: function (data) {             alert("dodanie  nie powiodło się " + data);         },         success: function (data) {             callback(data);         }     }); 

so problem in breaking execution of main event handler method. tried modifying lines:

self.searchkeyboardcmd = function (data, event,callback)  

and

foo(function (result) {                 console.log(result);                 callback(result);             }); 

the response i'm getting : undefined not function

try this:

var f = foo(function (result) {     if (result == 'false') {         alert("numer seryjny nie jest unikalny");         return true;     } });  if(!f){     return; // (or return true or false) } 

if f() returns false, code below function call won't executed, if returns true, be.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -