jQuery附加模板不更新

时间:2014-06-26 17:54:58

标签: jquery templates

我有一个模板,我附加了几个变量。新变量传递到模板时,模板不会更新。我在模板的div上使用.empty()方法进行了测试,但结果是一个空模板而不是新模板。将不胜感激任何帮助。我的JS是:

function InLineLinks(formController, fieldController) 
{ 
  ...

  self.showServerErrorPopup = function(serverError)
  {        
    console.log("showServerErrorPopup serverError=", serverError);
    jQuery('body').appendTemplate('inline-links:servererror-popup',{            
        containerID:"servererror",            
        serverError:serverError
    });            
    self.popupServerError = jQuery('#servererror').popup({                    
        'beforePopupClose': self.beforeServerPopupClose,
        'afterPopupOpen' : self.afterServerPopupOpen,});

    jQuery('#servererror').popup('show');
    jQuery('#servererror').focus();  
  };
  self.beforeServerPopupClose = function(){
    console.log("beforeServerPopupClose");
    if(self.popupServerError)
    {     

        $('#servererror').empty();
        self.popupServerError = null;
    }               
  };
 ...
} 

1 个答案:

答案 0 :(得分:0)

我通过测试div存在来实现它,并在创建新的之前将其删除:

self.showServerErrorPopup = function(serverError)
{        
    console.log("showServerErrorPopup serverError=", serverError);
    if($('#servererror').length)
    {
        $('#servererror').remove();
    }    
    jQuery('body').appendTemplate('inline-links:servererror-popup',{            
        containerID:"servererror",            
        serverError:serverError
    });            
    self.popupServerError = jQuery('#servererror').popup({                    
        'beforePopupClose': self.beforeServerPopupClose,
        'afterPopupOpen' : self.afterServerPopupOpen,});

    jQuery('#servererror').popup('show');
    jQuery('#servererror').focus(); 
}