首页 \ 问答 \ 来自json的jquery dform插件加载?(jquery dform plugin load from json?)

来自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
更新时间:2023-12-09 18:12

最满意答案

更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 ...
  • 我没有尝试,但我认为你可能正在寻找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 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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)