简体   繁体   English

Gon Gem for Rails上的红宝石观看功能观看所有变量

[英]Gon gem for ruby on rails watch function watch all variables

gon is a gem for ruby on rails to pass data from controller to view's javascript. gon是用于ruby的宝石,可将数据从控制器传递到视图的javascript。

It works fine,just pass data,and watch one variable. 它工作正常,只需传递数据并查看一个变量。

but when I have normal data(no need dynamic watch ) and data1 (need watch )teogeher,problem happens. 但是当我有正常的数据(不需要动态监视)和data1(需要监视)时,就会出现问题。

Gon watch all variables instead of only watch the gon.watch.data1. Gon监视所有变量,而不是仅监视gon.watch.data1。

That cause refresh time very very long (7k ms plus) 这会导致刷新时间非常长(超过7k ms)

web page always hang. 网页始终挂起。

anyone face this problem before? 有人遇到过这个问题吗? how to solve this? 如何解决呢?

code in my controller 我的控制器中的代码

class GmapsController < ApplicationController
  def index
    @i=0
    @Nstatic=Array.new(NoiseDevice.all.length) {Array.new(4)} 
    @Vstatic=Array.new(VibrationDevice.all.length) {Array.new(4)}     
    @vabrdevices = VibrationDevice.find(:all)

    @vabrdevices.each do |vabrdevice|
    @Vstatic[@i][0]=Project.where(id: vabrdevice.project_id).pluck(:client_name).first.to_s

    @Vstatic[@i][1]=vabrdevice.latitude #
    @Vstatic[@i][2]=vabrdevice.longitude #

    @Vstatic[@i][3]=VibrationDevice.where(id: vabrdevice.id).pluck(:cont_value).first.to_s

    @i+=1
    end

    @i=0
    @noiseDevices = NoiseDevice.find(:all)
    @noiseDevices.each do |noiseDevice|
    @Nstatic[@i][0]=Project.where(id: noiseDevice.project_id).pluck(:client_name).first.to_s
    address=Project.where(id: noiseDevice.project_id).pluck(:jobsite_location).first.gsub(/\s+/, "+")


    @Nstatic[@i][1]=noiseDevice.latitude #
    @Nstatic[@i][2]=noiseDevice.longitude #
    @Nstatic[@i][3]=NoiseDatum.order(:updated_at).where(noise_device_id: noiseDevice.id).pluck(:leq).first.to_s

    @i+=1
    end




    gon.nstatic=@Nstatic
    gon.vstatic=@Vstatic



    end

def ndataupdate
@test=Array.new
@test=VibrationDevice.pluck(:cont_value).to_s
gon.watch.test1=@test

end
end

Instead of update my test1 only, it updates all data which is loaded from database in this controller. 不仅更新了我的test1,它还更新了从该控制器中的数据库加载的所有数据。 even if I delete 即使我删除

gon.nstatic=@Nstatic gon.vstatic=@Vstatic gon.nstatic=@Nstatic gon.vstatic=@Vstatic

gon will load all data retrieved from database in this controller instead of part of it. gon将在此控制器中加载从数据库检索的所有数据,而不是其中的一部分。

In order to make it display only refresh part , I delete all retrieve data function ... 为了使其只显示刷新部分,我删除了所有检索数据功能...

maybe it's not answer, but maybe it somehow helps (comments are too long), 也许不是答案,但也许会有所帮助(评论过长),

so, you could specify manualy url for updating variable like: 因此,您可以指定手动url来更新变量,例如:

gon.watch('test1', {interval: <ms>, url: '<url>'}, '<callback>')

for checking available variables in your ndataupdate action you could write: 为了检查ndataupdate操作中的可用变量,您可以编写:

gon.all_variables

also you could try cleaning variables with: 您也可以尝试使用以下方法清理变量:

gon.clear

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

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