- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在下面的代码中, "$('#movesindexrowstable').DataTable({..."永远不会触发。但是, "$('#movesindexlotstable').DataTable({..."工作得很好。
有趣的是, Controller “移动”操作“indexrows”呈现状态为 200,但模板不会执行,因为其中的断点不会触发。当然,如果未执行模板,则不会处理 ID movesindexrowstable,这解释了为什么 jQuery 代码不会触发。
渲染代码 MovesIndexlotsDatatable 和 MovesIndexrowsDatatable 返回有效的 JSON。当然,即使没有,也不应该影响渲染对模板的使用吧?
考虑到可能涉及涡轮链接,我将第一行更改为使用 page:change 而不是常见的“$(document).ready(function () {”以符合其要求。这没有帮助,也没有帮助确实添加了数据无涡轮链接。
我通过 jquery-datatables-rails 使用 DataTables 和 AJAX 来显示表中的 JSON 数据。但是,DataTables 永远不会获得控制权,因为选择器永远不会被识别,并且该函数不会触发。
这让我很困惑,希望得到任何帮助。谢谢。
编辑:我相信下图即使不是解决方案,也能隔离问题。 Moves#Indexlots 的初始 GET 呈现模板,后续 POST 提供数据但不呈现模板。到目前为止,我的编码仅包括 Moves#Indexrows 数据的 POST。看来我需要说服 POST 来渲染模板,或者找到一种替代方法,例如通过 GET?如果是这样,我想要有关如何做到这一点的建议。谢谢。
编辑:看起来像/一个答案? Render an HTML partial inside a JSON request
编辑:在 JQ 中,我将“$.post('/moves_indexrows.json'”更改为“$.post('/moves_indexrows.html'”。这导致 POST 呈现预期的结果页面。网络跟踪显示页面大小为 15.6KB。Rails 跟踪显示渲染的 ERB 文件。即使浏览器看到了所有这些,也没有发生页面更改!我真的不知道了解这一点。显示为:
jQuery/JavaScript 代码:
$(document).on('page:change', function(){
// AJAX DataTable Moves Lots for bulk moves
var lots_active = [];
var movesindexlotstable = $('#movesindexlotstable').DataTable({
responsive: true,
autoWidth: false,
pagingType: 'full',
jQueryUI: false,
processing: true,
serverSide: true,
ajax: {
url: 'moves_indexlots.json',
type: 'POST',
contentType: 'application/json',
dataType: 'json',
data: function (d) {
return JSON.stringify(d);
}
},
columns: [
{"data": "name", className: null}
],
rowCallback: function (row, data) {
if ($.inArray(data.DT_RowId, lots_active) !== -1) {
$(row).addClass('active');
}
}
});
$('#movesindexlotstable tbody').on('click', 'tr', function () {
var id = this.id;
var index = $.inArray(id, lots_active);
if (index === -1) {
lots_active.push(id);
} else {
lots_active.splice(index, 1);
}
$(this).toggleClass('active');
});
// Ajax moves, select lots
$('#movesindexlotsbutton').on('click', function () {
var source = 'lots';
$.post('/moves_indexrows.json',
{
commit: 'Moves Lots',
source: source,
active: lots_active
}
);
return false;
});
// AJAX DataTable Moves Rows within Lots for bulk moves
var rows_active = [];
var movesindexrowstable = $('#movesindexrowstable').DataTable({
responsive: true,
autoWidth: false,
pagingType: 'full',
jQueryUI: false,
processing: true,
serverSide: true,
ajax: {
url: 'moves_indexrows.json',
type: 'POST',
contentType: 'application/json',
dataType: 'json',
data: function (d) {
return JSON.stringify(d);
}
},
columns: [
{"data": "name", className: null}
],
rowCallback: function (row, data) {
if ($.inArray(data.DT_RowId, rows_active) !== -1) {
$(row).addClass('active');
}
}
});
$('#movesindexrowstable tbody').on('click', 'tr', function () {
var id = this.id;
var index = $.inArray(id, rows_active);
if (index === -1) {
rows_active.push(id);
} else {
rows_active.splice(index, 1);
}
$(this).toggleClass('active');
});
// Ajax moves, select rows from selected lots
$('#movesindexrowsbutton').on('click', function () {
var source = 'rows';
$.post('/moves_indexcars.json',
{
commit: 'Moves Rows',
source: source,
active: rows_active
}
);
return false;
});
});
RoR代码:
class MovesController < ApplicationController
before_action :check_if_associate
def indexlots
respond_to do |format|
format.html
format.json { render json: MovesIndexlotsDatatable.new(view_context) }
end
end
def indexrows
lots = Array.new
params[:active].map { |lot| id = lot[4..(lot.length-1)].to_i; lots << Lot.find(id); }
respond_to do |format|
format.html
format.json { render json: MovesIndexrowsDatatable.new(view_context, lots) }
end
end
end
moves/indexlots.html.erb
<div class="row">
<%= render partial: 'indexlots', layout: 'layouts/kac_label', locals: {title: 'Moves Cars - Lots' } %>
</div>
moves/indexrows.html.erb
<div class="row">
<%= render partial: 'indexrows', layout: 'layouts/kac_label', locals: { title: 'Moves Cars - Rows' } %>
</div>
移动/_indexlots.html.erb
<div class="form-group span8">
<table id="movesindexlotstable" class="display dt-responsive no-wrap table-striped" cellspacing="0" width="80%">
<thead>
<tr>
<th class="all"><b>Lot</b></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class='break_line'></div>
<input type="submit" name="commit" value="Select Lots" id="movesindexlotsbutton" class="btn btn-primary kc-wide" data-no-turbolink data-disable-with="Processing">
<%= link_to 'Home', '/', class: 'btn btn-primary kc-wide' %>
</div>
moves/_indexrows.html.erb
<div class="form-group span8">
<table id="movesindexrowstable" class="display dt-responsive no-wrap table-striped" cellspacing="0" width="80%">
<thead>
<tr>
<th class="all"><b>Rows</b></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class='break_line'></div>
<input type="submit" name="commit" value="Select Rows" id="movesindexrowsbutton" class="btn btn-primary kc-wide" data-no-turbolink data-disable-with="Processing">
<%= link_to 'Home', '/', class: 'btn btn-primary kc-wide' %>
</div>
日志:
...
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on 127.0.0.1:3000, CTRL+C to stop
Started GET "/moves_indexlots" for 127.0.0.1 at 2016-02-20 16:58:32 -0500
ActiveRecord::SchemaMigration Load (1.0ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by MovesController#indexlots as HTML
Company Load (0.5ms) SELECT "companies".* FROM "companies" WHERE "companies"."prefix" = $1 LIMIT 1 [["prefix", "ucf"]]
Company Load (0.0ms) SELECT "companies".* FROM "companies" WHERE "companies"."prefix" = $1 ORDER BY "companies"."id" ASC LIMIT 1 [["prefix", "ucf"]]
CACHE (0.0ms) SELECT "companies".* FROM "companies" WHERE "companies"."prefix" = $1 LIMIT 1 [["prefix", "ucf"]]
Associate Load (1.0ms) SELECT "associates".* FROM "associates" WHERE "associates"."company_id" = $1 AND "associates"."id" = $2 LIMIT 1 [["company_id", 1], ["id", 74]]
Role Load (0.5ms) SELECT "roles".* FROM "roles" INNER JOIN "associates_roles" ON "roles"."id" = "associates_roles"."role_id" WHERE "associates_roles"."associate_id" = $1 AND (((roles.name = 'associate') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL))) [["associate_id", 74]]
CACHE (0.0ms) SELECT "companies".* FROM "companies" WHERE "companies"."prefix" = $1 LIMIT 1 [["prefix", "ucf"]]
Rendered moves/_indexlots.html.erb (8.0ms)
Rendered moves/indexlots.html.erb within layouts/application (17.5ms)
Action#Controller is indexlots#moves
Rendered layouts/_shim.html.erb (1.0ms)
Role Load (0.5ms) SELECT "roles".* FROM "roles" INNER JOIN "associates_roles" ON "roles"."id" = "associates_roles"."role_id" WHERE "associates_roles"."associate_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL))) [["associate_id", 74]]
Rendered layouts/_navigation_links.html.erb (12.5ms)
Rendered layouts/_navigation.html.erb (15.0ms)
Rendered layouts/_messages.html.erb (1.0ms)
Completed 200 OK in 2386ms (Views: 2103.0ms | ActiveRecord: 7.5ms)
Started POST "/moves_indexlots.json" for 127.0.0.1 at 2016-02-20 16:58:35 -0500
Processing by MovesController#indexlots as JSON
Parameters: {"draw"=>1, "columns"=>[{"data"=>"name", "name"=>"", "searchable"=>true, "orderable"=>true, "search"=>{"value"=>"", "regex"=>false}}], "order"=>[{"column"=>0, "dir"=>"asc"}], "start"=>0, "length"=>10, "search"=>{"value"=>"", "regex"=>false}, "move"=>{"draw"=>1, "columns"=>[{"data"=>"name", "name"=>"", "searchable"=>true, "orderable"=>true, "search"=>{"value"=>"", "regex"=>false}}], "order"=>[{"column"=>0, "dir"=>"asc"}], "start"=>0, "length"=>10, "search"=>{"value"=>"", "regex"=>false}}}
Company Load (0.5ms) SELECT "companies".* FROM "companies" WHERE "companies"."prefix" = $1 LIMIT 1 [["prefix", "ucf"]]
Company Load (1.0ms) SELECT "companies".* FROM "companies" WHERE "companies"."prefix" = $1 ORDER BY "companies"."id" ASC LIMIT 1 [["prefix", "ucf"]]
CACHE (0.0ms) SELECT "companies".* FROM "companies" WHERE "companies"."prefix" = $1 LIMIT 1 [["prefix", "ucf"]]
Associate Load (0.5ms) SELECT "associates".* FROM "associates" WHERE "associates"."company_id" = $1 AND "associates"."id" = $2 LIMIT 1 [["company_id", 1], ["id", 74]]
Role Load (1.0ms) SELECT "roles".* FROM "roles" INNER JOIN "associates_roles" ON "roles"."id" = "associates_roles"."role_id" WHERE "associates_roles"."associate_id" = $1 AND (((roles.name = 'associate') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL))) [["associate_id", 74]]
(1.5ms) SELECT COUNT(*) FROM "lots" WHERE "lots"."company_id" = $1 [["company_id", 1]]
CACHE (0.0ms) SELECT COUNT(*) FROM "lots" WHERE "lots"."company_id" = $1 [["company_id", 1]]
Lot Load (0.5ms) SELECT "lots".* FROM "lots" WHERE "lots"."company_id" = $1 ORDER BY name asc LIMIT 10 OFFSET 0 [["company_id", 1]]
Completed 200 OK in 195ms (Views: 52.5ms | ActiveRecord: 7.5ms)
Started POST "/moves_indexrows.json" for 127.0.0.1 at 2016-02-20 16:58:41 -0500
Processing by MovesController#indexrows as JSON
Parameters: {"commit"=>"Moves Lots", "source"=>"lots", "active"=>["Row_64", "Row_29"]}
Company Load (0.5ms) SELECT "companies".* FROM "companies" WHERE "companies"."prefix" = $1 LIMIT 1 [["prefix", "ucf"]]
Company Load (0.0ms) SELECT "companies".* FROM "companies" WHERE "companies"."prefix" = $1 ORDER BY "companies"."id" ASC LIMIT 1 [["prefix", "ucf"]]
CACHE (0.0ms) SELECT "companies".* FROM "companies" WHERE "companies"."prefix" = $1 LIMIT 1 [["prefix", "ucf"]]
Associate Load (0.5ms) SELECT "associates".* FROM "associates" WHERE "associates"."company_id" = $1 AND "associates"."id" = $2 LIMIT 1 [["company_id", 1], ["id", 74]]
Role Load (0.5ms) SELECT "roles".* FROM "roles" INNER JOIN "associates_roles" ON "roles"."id" = "associates_roles"."role_id" WHERE "associates_roles"."associate_id" = $1 AND (((roles.name = 'associate') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL))) [["associate_id", 74]]
Lot Load (0.5ms) SELECT "lots".* FROM "lots" WHERE "lots"."company_id" = $1 AND "lots"."id" = $2 LIMIT 1 [["company_id", 1], ["id", 64]]
Lot Load (0.5ms) SELECT "lots".* FROM "lots" WHERE "lots"."company_id" = $1 AND "lots"."id" = $2 LIMIT 1 [["company_id", 1], ["id", 29]]
(1.0ms) SELECT COUNT(*) FROM "rows" WHERE "rows"."company_id" = $1 [["company_id", 1]]
Row Load (0.0ms) SELECT "rows".* FROM "rows" WHERE "rows"."company_id" = $1 AND (lot_id = 64) ORDER BY name asc [["company_id", 1]]
Row Load (0.5ms) SELECT "rows".* FROM "rows" WHERE "rows"."company_id" = $1 AND (lot_id = 29) ORDER BY name asc [["company_id", 1]]
(0.5ms) SELECT COUNT(*) FROM "rows" WHERE "rows"."company_id" = $1 AND "rows"."id" IN (186, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144) [["company_id", 1]]
CACHE (0.0ms) SELECT "rows".* FROM "rows" WHERE "rows"."company_id" = $1 AND (lot_id = 64) ORDER BY name asc [["company_id", 1]]
CACHE (0.0ms) SELECT "rows".* FROM "rows" WHERE "rows"."company_id" = $1 AND (lot_id = 29) ORDER BY name asc [["company_id", 1]]
Row Load (0.5ms) SELECT "rows".* FROM "rows" WHERE "rows"."company_id" = $1 AND "rows"."id" IN (186, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144) LIMIT 10 OFFSET 0 [["company_id", 1]]
CACHE (0.0ms) SELECT COUNT(*) FROM "rows" WHERE "rows"."company_id" = $1 AND "rows"."id" IN (186, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144) [["company_id", 1]]
Completed 200 OK in 213ms (Views: 86.3ms | ActiveRecord: 6.9ms)
MovesIndexlotsDatatable JSON:
"{"draw":1,"recordsTotal":57,"recordsFiltered":57,"data":[{"DT_RowId":"Row_64","name":"auction"},{"DT_RowId":"Row_29","name":"Buying-Ctr"},{"DT_RowId":"Row_30","name":"Buying-Ctr-Corrider A-H"},{"DT_RowId":"Row_27","name":"Buying-Ctr-Corrider B-G"},{"DT_RowId":"Row_31","name":"Buying-Ctr-Corrider C-F"},{"DT_RowId":"Row_32","name":"Buying-Ctr-Corrider D-E"},{"DT_RowId":"Row_36","name":"Buying-Ctr-Corrider E-L"},{"DT_RowId":"Row_35","name":"Buying-Ctr-Corrider F-K"},{"DT_RowId":"Row_34","name":"Buying-Ctr-Corrider G-J"},{"DT_RowId":"Row_33","name":"Buying-Ctr-Corrider H-I"}]}"
MovesIndexrowsDatatable JSON:
"{"draw":1,"recordsTotal":92,"recordsFiltered":14,"data":[{"DT_RowId":"Row_133","name":" A"},{"DT_RowId":"Row_134","name":" B"},{"DT_RowId":"Row_135","name":" C"},{"DT_RowId":"Row_136","name":" D"},{"DT_RowId":"Row_137","name":" E"},{"DT_RowId":"Row_138","name":" F"},{"DT_RowId":"Row_139","name":" G"},{"DT_RowId":"Row_140","name":" H"},{"DT_RowId":"Row_141","name":" I"},{"DT_RowId":"Row_142","name":" J"}]}"
最佳答案
TL/DR:转换为使用 JavaScript 作为 SPA 和 Rails 作为 HTML/数据微服务。
基本问题似乎是,当某个操作是从 JavaScript 发起时,Rails 并没有完全意识到该操作并对此感到满意。它将运行并使用 HTTP 200 进行渲染,但渲染结果不显示。我运行了跟踪,将标准操作与 JavaScript 启动的操作进行比较,但没有发现处理过程中的差异。我假设有一些内部变量通常在启动时设置,而不是通过 JavaScript 设置,从而导致了此问题。但是,我没有找到。
不过,我确实解决了这个问题。基本上我把这个过程变成了 SPA(单页应用程序)。第一个操作是标准 Rails,但它会在用户第一次交互或单击按钮时将其交给 JavaScript。从那时起,JavaScript 运行该流程,使用 AJAX POST 在一个操作中查询 Rails 的 HTML,在另一个操作中查询数据,从而将其作为一项微服务使用。然后 JavaScript 呈现结果页面,等待再次单击,然后继续。最后一页提供了再次恢复到 Rails 标准处理的按钮。
这就是我的故事,我会坚持下去。谢谢。
PS。我应该提到的是,在一次性的情况下,用 JS 触发一个 Action 对我来说很有效。我的问题是需要经过几层屏幕,每层都通过 JS 触发,因为每次我都有信息从 JS 传递回操作。在一次性情况下,我只是使用以下操作发回控制权:render js: "window.location.assign(location.origin + '/item')" unless performed?
关于javascript - Rails 操作以状态 200 运行,但未访问模板且未触发 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35529619/
这个问题已经有答案了: jQuery trigger click vs click ()? (3 个回答) 已关闭 5 年前。 我无法区分 trigger('click')与 trigger('cli
我正在运行 VS 2008 和 .NET 3.5 SP1。 我想在 HttpModule 中实现命中跟踪在我的 ASP.NET 应用程序中。很简单,我想。然而,BeginRequest我的事件 Htt
这是一段代码,我收到以下错误 #1064 - You have an error in your SQL syntax; check the manual that corresponds to yo
有没有办法用任意增量触发滚轮事件。就像 jQuery 对“点击”所做的那样: $('#selector').trigger('click'); 我需要类似的东西,只需一个滚轮即可: $('#selec
我正在尝试在配音数据库中触发时间。我想检查一下在不出现角色的电影配音中不能对角色进行配音。这是PDM: 和CDM 我是SQL的初学者,但我知道表“DUBBES”中应该有一些触发器。我试图做这样的事情,
这个问题已经有答案了: jquery programmatically click on new dom element (3 个回答) 已关闭 6 年前。 我有一个 jQuery 事件定义如下: $
主菜单的点击代码适用于类更改,但不适用于子菜单...当单击食物或鞋子等子菜单项时,它不会触发警报命令...事实上,悬停非常适合子菜单但不是活跃的 HTML
问题非常简单: $('#btn1').click(function(event){ alert( "pageX: " + event.pageX + "\npa
我使用 Spring 的调度程序 (@EnableScheduling) 并具有以下 @Scheduled 方法,该方法每分钟调用一次: @Component public class Schedul
错误 SQL 查询:文档 CREATE TRIGGER `triggers_div` AFTER INSERT ON `produits` FOR EACH ROW BEGIN INSERT INTO
我想在插入另一个表时填充表中的一些列值,并为特定列设置条件。我使用触发器: CREATE TRIGGER inserttrigger AFTER INSERT ON table1 FOR EACH R
我可以在 5.6 MySQL 环境中使用一些关于触发器的指导。我想创建一个触发器,如果发现具有相同速度的电脑的价格较低,则该触发器会停止更新。 架构是产品(制造商、型号、类型)PC(型号、速度、内
背景:我们有一个 completed_flag,默认为 0,当有人完成调查时更新为 1。我想记录这次更新发生的时间戳 在编写了这个触发器/函数以在标志从 0 触发到 1 时更新时间戳后,我怀疑我这样做
数据库中有两个表 KistStatus和 LastKistStatus .后者将保存 KistStatus 的所有“最新”值。 . KistStatus有大约 174.000 条记录,LastKist
我正在开发一个使用 APNS 的 iPhone 应用程序。我很清楚实现 APNS、创 build 备 token 的过程,等等等等……我不知道如何通过 Web 服务从提供商端触发和启动 APNS。任何
我有这个 javascript,当数量更改时会触发 update_cart... jQuery('div.woocommerce').on('change', '.qty', function
当我单击任何按钮时,click 事件不会被触发。艰难的是,我使用 $("div").on("click", "button", function () { 让它工作,但我想看到它使用 .class 工
如何在我的代码中触发 Android onCreateOptionsMenu 函数,即无需用户单击手机上的选项菜单按钮? 最佳答案 Activity.openOptionsMenu(); 就可以了 关
我将表单包装在 中然后我设置 list android:windowSoftInputMode="adjustResize" (默认 react native )。现在,当我用手指触摸事件手动聚焦一
我有一个 Android 编程问题。使用下面的代码我想验证一个字符串匹配。它验证正常,但 LogCat 显示 TextWatcher 方法在每次击键时触发两次,我不明白为什么。我希望每次击键只触发一次
我是一名优秀的程序员,十分优秀!