简体   繁体   English

骨干模型绑定器转换器ajax请求

[英]backbone modelbinder converter ajax request

Does anyone know how to cause modelbinder's converter to wait until a ajax request is complete? 有谁知道如何使modelbinder的转换器等待ajax请求完成? I'm trying to use backbone's modelbinder on my view but the converter is failing because it is not waiting for the ajax call to complete before rendering 我正在尝试在视图上使用骨干的modelbinder,但转换器失败,因为它没有等待ajax调用在渲染之前完成

var convertIdToName = function(direction, value) {
   if(direction == 'ModelToView') { 
      $.ajax({url: 'rest/lookup?' + value}).done(data) { 
        return data[0].Name; }
   }
}

var binding = {Id: { selector: '[name=Id]', converter: convertIdToName }};

I fixed this by seting 我通过设置解决了

  async: false 

on ajax request 在ajax请求

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM