来自json的jquery dform插件加载?(jquery dform plugin load from json?)
我正在使用JQuery dForm插件来创建表单。 它使用以下代码:
$("#myform").dform({ "action" : "index.html", "method" : "get", "html" : [ { "type" : "p", "html" : "You must login" }, { "name" : "username", "id" : "txt-username", "caption" : "Username", "type" : "text", "placeholder" : "E.g. user@example.com" }, { "name" : "password", "caption" : "Password", "type" : "password" }, { "type" : "submit", "value" : "Login" } ] });
但是,如果我将表单定义移动到JSON文件,如:
"action" : "index.html", "method" : "get", "html" : [ { "type" : "p", "html" : "You must login" }, { "name" : "username", "id" : "txt-username", "caption" : "Username", "type" : "text", "placeholder" : "E.g. user@example.com" }, { "name" : "password", "caption" : "Password", "type" : "password" }, { "type" : "submit", "value" : "Login" } ]
并尝试从json加载表单定义:
$("#myform").dform('test.json', function(data) { this //-> Generated $('#myform') data //-> data from path/to/form.json });
表单不加载。 我是否需要在JSon文件或代码中添加其他内容?
任何帮助深表感谢。
谢谢,卡洛斯
I am using JQuery dForm plugin to create a form. It works with the following code:
$("#myform").dform({ "action" : "index.html", "method" : "get", "html" : [ { "type" : "p", "html" : "You must login" }, { "name" : "username", "id" : "txt-username", "caption" : "Username", "type" : "text", "placeholder" : "E.g. user@example.com" }, { "name" : "password", "caption" : "Password", "type" : "password" }, { "type" : "submit", "value" : "Login" } ] });
But If I move the form definition into a JSON file like:
"action" : "index.html", "method" : "get", "html" : [ { "type" : "p", "html" : "You must login" }, { "name" : "username", "id" : "txt-username", "caption" : "Username", "type" : "text", "placeholder" : "E.g. user@example.com" }, { "name" : "password", "caption" : "Password", "type" : "password" }, { "type" : "submit", "value" : "Login" } ]
And try to load the form definition from the json with:
$("#myform").dform('test.json', function(data) { this //-> Generated $('#myform') data //-> data from path/to/form.json });
The form does not load. Do I need to put something else in the JSon file or in the code?
Any help is much appreciated.
Thanks, Carlos
原文:https://stackoverflow.com/questions/19708583
最满意答案
更Ruby的方法是使用内部函数来处理这个:
module MyModule def analyze_log logfile = '/www/redmine/log/logfile.log' [ "#{logfile}.0", logfile ].each do |file| File.readlines(file).each do |line| print line end end end end
运行子进程来读取文件是完全没必要的。
A more Ruby way of doing this is to use internal functions to handle this:
module MyModule def analyze_log logfile = '/www/redmine/log/logfile.log' [ "#{logfile}.0", logfile ].each do |file| File.readlines(file).each do |line| print line end end end end
Running a sub-process to read a file is completely unnecessary.
相关问答
更多-
记录器是rails的一部分 irb只是一个ruby命令行解释器 使用'rails console'获取运行rails infrastructure的命令行界面。 使用irb时使用puts作为记录器的替代品 编辑 你永远不会尝试在irb中运行该代码,而是将文件复制到yourapp / lib,然后执行 rails console 现在启动RAILS,但是使用命令行界面,然后尝试 包括LinkedIn :: Api :: QueryMethods 测试 现在你也可以使用logger.debug logger i ...
-
在irb中重新加载rubygems?(Reload rubygems in irb?)[2022-11-23]
我没有尝试,但我认为你可能正在寻找Gem.clear_paths 重置目录和路径值。 下一次请求目录或路径时,将从头开始计算值。 这主要是由单元测试用来提供测试隔离。 I did not try, but I think you might be looking for Gem.clear_paths Reset the dir and path values. The next time dir or path is requested, the values will be calculated fro ... -
在irb中, File.expand_path(__FILE__)}将返回"#{path you ran irb from}/(irb)" 。 它创建一个实际不存在的路径。 幸运的是,所有文件路径都是相对于你运行irb的地方。 这意味着你需要的是: load "lib/query.rb" 如果你想在实际的文件中使用__FILE__ ,那没关系,但是不要指望它在irb中产生一个有效的路径。 因为irb根本没有“文件”,所以它根本不能返回有效的路径。 另外, __FILE__可以正常工作,如果在加载到irb的 ...
-
因为你的一个用户没有任何组织,所以organizational.first首先是零 你可以通过做这件事来防止 User.find(:all).select {|u| u.organizations.first.name unless u.organizations.size == 0} Because one of your users does not have any organizations so organizations.first is nil You can prevent this ...
-
我不知道SerialPort gem,但是可能是缓冲输出到串口,并且在脚本退出之前没有刷新,而IRB在返回提示时给它时间来刷新缓冲区。 我尝试添加@sp.flush ,看看是否有帮助。 I don't know the SerialPort gem, but it's possible that output to the serial port is being buffered, and not flushed before the script exits, while IRB gives it ti ...
-
更Ruby的方法是使用内部函数来处理这个: module MyModule def analyze_log logfile = '/www/redmine/log/logfile.log' [ "#{logfile}.0", logfile ].each do |file| File.readlines(file).each do |line| print line end end end end 运 ...
-
Rails - IRB是否必要?(Rails — is IRB necessary?)[2022-03-02]
有关单独的脚本,请查看rails runner 。 它加载Rails后端,因此您可以访问所有模型并为此目的而存在。 来自“ Ruby on Rails指南 ”: runner以非交互方式在Rails的上下文中运行Ruby代码。 例如: $ rails runner“Model.long_running_method” For a separate script look into rails runner. It loads the Rails backend so you have access to a ... -
您可以按ctrl + c,然后返回以获取IRB的提示。 You can press ctrl + c followed by return to get back IRB's prompt.
-
这不是你正在寻找的东西,但方法确实有一个.source_location方法。 你可以用它来找出实际实现类的地方。 (由于ruby让你重新开放课程,这可能会在多个地方) 例如,给定一个对象的实例, 我 : i.methods.map do |method_name| method_obj = i.method(m) file, line = method_obj.source_location file #map down to the file name end.uniq 会给你一个所有我 ...
-
您需要在要应用它的类中定义方法。 class NewObject def foo puts "hello" end end 这些方法被称为: x = NewObject.new x.foo 您可以通过定义方法来创建不特定于类的方法: def bar puts "bar!" end 并将它们称为: bar You need to define the method in the class you want it to apply to. class NewObject ...