Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通行证;这";在承诺内?_Javascript_Jquery_Ajax_Promise - Fatal编程技术网

Javascript 通行证;这";在承诺内?

Javascript 通行证;这";在承诺内?,javascript,jquery,ajax,promise,Javascript,Jquery,Ajax,Promise,我正在努力学习承诺 我的URL将包含三个ID参数,例如 #org=123&num=145&denom=467 我想用它们来选择页面上三个select元素的值(每个元素都有一个Ajax源代码),例如 任何关于我这样做的其他建议也将被感激地接受 可以使用()/传递自定义执行上下文 setFormValues: function() { return _this.getOrgs() .then(_this.getNumerators.bind(_this)) //us

我正在努力学习承诺

我的URL将包含三个ID参数,例如

#org=123&num=145&denom=467
我想用它们来选择页面上三个
select
元素的值(每个元素都有一个Ajax源代码),例如

任何关于我这样做的其他建议也将被感激地接受

可以使用()/传递自定义执行上下文

setFormValues: function() { 
  return _this.getOrgs()
     .then(_this.getNumerators.bind(_this)) //using bind() - supported in IE9+
     .then($.proxy(_this.getDenominators, _this)) //using $.proxy()
     .then(function() {
        return true;
        }
    });
 }
或者可以使用ajax中的上下文选项传递自定义上下文

getOrgs: function() { 
    return $.ajax({
        type: 'GET',
        url:'/api/orgs/?q=' + this.globalOptions.orgId,
        dataType: 'json',
        context: this
    });
},

你能提供更多关于如何使用这些函数的代码吗?可能是Brilliant的重复,谢谢-上下文:这个选项对我有效。
setFormValues: function() { 
  return _this.getOrgs()
     .then(_this.getNumerators.bind(_this)) //using bind() - supported in IE9+
     .then($.proxy(_this.getDenominators, _this)) //using $.proxy()
     .then(function() {
        return true;
        }
    });
 }
getOrgs: function() { 
    return $.ajax({
        type: 'GET',
        url:'/api/orgs/?q=' + this.globalOptions.orgId,
        dataType: 'json',
        context: this
    });
},