javascript - 如何将数据从 processing.js 序列化到 Rails 应用程序?

标签 javascript ruby-on-rails ajax processing

我正在使用 processing.js 创建一个简单的 Canvas ,如何将值从 Rails 应用程序传递到 Processing.js

void drawBox(int bx, int by, int bs, int bs){
      strokeWeight(3); 
      stroke(50,50,50);
      // Test if the cursor is over the box 
      if (mouseX > bx-bs && mouseX < bx+bs && 
          mouseY > by-bs && mouseY < by+bs) {
        bover = true;
       if(!locked) { 
          fill(181,213,255);
        } 
      } else {
        fill(255);
          bover = false;
      }
      fill(192);
      stroke(64);
      roundRect(bx, by,80,30,10,10);
      // put in text 
      if (!isRight) {
        text("Box Value", x-size+5, y-5);
      //Here i need to pass value from my controller
      }
      else {
        text("Box Value", x+5, y-5);  
 //Here i need to pass value from my controller    
      }
    }

我需要通过 ajax 传递来自 ex @post.name 的值,而不是静态字符串 "Box Value"

最佳答案

我会使用一些 RJS 模板来执行此操作,您可以在其中为文本设置全局变量或使用数据存储将其附加到 DOM 元素。然后在您的 processing.js 中,只需使用该变量来呈现您的文本。

关于javascript - 如何将数据从 processing.js 序列化到 Rails 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2462219/

相关文章:

ruby-on-rails - 具有共享布局的独立命名空间的 Rails 引擎

ruby-on-rails - 如何解决“DL 已弃用,请使用 Fiddle”Rails 4.1.8?

ruby-on-rails - 如何在 localhost 中使用 rails plus paperclip 和 fog

javascript - jquery 占位符,而 ajax 加载下拉菜单

javascript - Angular2 react 形式下拉

javascript - 使用 JQuery、Ajax、PHP 和 MySQL 的多个文本框字段

javascript - 是否可以克隆 ES6 promise ?

javascript - 每次调整大小时都会加载图像吗?

javascript - 位置 4 的 JSON 中的意外标记 <

ruby-on-rails - rails/Ajax : Unable to remove "bullet mark" when using Ajax in Rails to add Todos remotely