【问题标题】:how to get value of field in jquery jtable如何在jquery jtable中获取字段的值
【发布时间】:2020-02-08 10:42:56
【问题描述】:

我在j-table 中有一个drop-down,我想从中提取selected value。有没有办法从 j-table 中获取 selected option 值。

sections_template_id: {
  title: 'Template',
  inputTitle: "Template*",
  options: web_sections,
  create: true,
  edit: true,
  list: true                
}
, sec_hidden: {
type: 'hidden'
  , inputTitle: "Template*"
  , create: true
  , edit: false
  , list: false
  , defaultValue: web_sections
   }

我想在sec_hidden中设置sections_template_id的值

这是我调用函数的路线

 Route::post('cms-web-section-templates',['as' => 'cms-web-section-templates', 'uses' => 'CmsController@Main_sections']);

这是我的功能

public function Main_sections(Request $request)
    {
        $types = SectionType::getTypes();

      $web_section = WebTemplate::all();

     //dd($web_section);

        $rows[] = array("DisplayText"=>"", "Value"=>"");

        foreach ($web_section as $key => $web_sections) {
            $rows[] = array(
                'DisplayText' => $web_sections->name,
                'Value' => $web_sections->id,
            );
        }

        $this->response['Options'] = $rows;
        $this->response['Result'] = "OK";
        return json_encode($this->response);
    }

【问题讨论】:

  • 你能提供一个你的代码的工作示例吗?
  • @obscure 如果你能帮助我,我确实编辑了我的问题
  • 你能显示表格和下拉选择吗?
  • @user10971804 发布的代码很长..sections_template_id: { title: 'Template', inputTitle: "Template*", options: web_sections, create: true, edit: true, list: true }这是我想要获取的 id 部分的选择
  • 只需像 $('#selectID').on('change',function(){ var value = $(this).val();}) 这样通过 selectID 获取数据。如果选择器是一个类,这仍然有效。

标签: javascript jquery jquery-jtable


【解决方案1】:

我使用 jquery/javascript 从jtable 获取数据。我在 jtable 文档中找不到如何获取所选值。如果您检查元素,一旦您选择了该行,就会在该行中添加一个“jtable-row-selected”类。

<script>
        var all_rows = [];
        $('tr.jtable-row-selected').each(function(){
            var len = $(this).children().length;
            var row = [];
            for(let i = 0;i < len; i+=1){
                row.push($(this).children()[i].innerText)
            }
            all_rows.push(row);
        })
        //console.log(all_rows);
    </script>

【讨论】:

    【解决方案2】:

    试试jtableselectedRows方法,获取选中行的jquery对象。

    https://jtable.org/ApiReference/Methods#met-selectedRows 文档有一个简短的示例,如何获取每个选定行的记录和字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-12
      相关资源
      最近更新 更多