[英]Is there a simple way to only reload an element if it content has changed?
I am using RightJS (very similar to jQuery) on a site I'm working on. 我在我正在处理的网站上使用RightJS(非常类似于jQuery)。 I am loading an element on the page with the result of a request like so:
我正在将页面的元素加载到请求的结果中,如下所示:
var comp = $('completed_step');
if(comp != null) comp.load("/brew/completed_step");
This works but I am trying to find a way to only load the element if the result of the request for 'brew/current_step' is different than the value currently loaded in the element. 这可行,但是我试图找到一种方法,仅在请求“ brew / current_step”的结果与当前加载到元素中的值不同时才加载元素。 Is there an easy way to accomplish that?
有没有简单的方法可以做到这一点?
You need to compare the value of the current element with what is loaded. 您需要将当前元素的值与加载的内容进行比较。
var comp2;
var comp = $('completed_step'); //I'm assuming this refers to some value
if( comp != null || comp != "" ){
comp2 = load("/brew/completed_step");
}
if( comp != comp2 ){
comp = comp2;
}
Keep in mind, I'm not familiar with RightJS, so this might be wrong, but should give you the right idea. 请记住,我对RightJS不熟悉,所以这可能是错误的,但是应该给您正确的想法。
Edit: 编辑:
It looks like the Xhr module in rightJS takes an object that allows you to specify what to do when the process has completed. 看起来rightJS中的Xhr模块采用了一个对象,该对象使您可以指定过程完成后的操作。
http://rightjs.org/docs/xhr#load http://rightjs.org/docs/xhr#load
Xhr.load('/some/url', {
onSuccess: function(request) {
// do something about it
}
});
That's from their example in the documentation. 这是从文档中的示例中得出的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.