简体   繁体   English

有一种简单的方法可以仅在元素的内容已更改时重新加载它吗?

[英]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.

相关问题 有没有办法找出 iframe 的内容是否已更改? - Is there a way to find out if the content of an iframe has changed? 仅在添加/更改数据库记录时如何重新加载表内容 - How to reload table content only whenever a database record is added/changed jQuery-将json内容绑定到元素的简单方法? - jQuery - simple way to bind json content to element? 仅在值更改时重新加载 - reload only when value is changed 仅当内容在500毫秒内未更改时才执行操作 - Only do an action if content has not changed in 500ms 仅当来自ajax调用的数据发生更改时才更新内容 - Update content only if data from ajax call has changed 有没有办法检测可观察的嵌套结构的任何元素是否已经改变? - Is there a way to detect whether any element of a nested structure of observables has changed? 仅当网页中的特定值发生更改时,才如何更新/重新加载该值? (使用html / javascript) - How to update/reload a particular value in a web page only if it has changed? (using html/javascript) 有没有办法使元素可点击,但前提是它有文本? - Is there a way to make an element clickable but only if it has text in it? 一旦div中的内容发生更改,就会在页面中重新加载javascript - reload javascript in a page once the content in the div is changed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM