我的表格通过ajax添加了新行。
_group.html.erb
$("#grouptable").prepend('<%= j render(@group)%>');
create.js.rb
<table class="table table-striped">
<thead>
<tr>
<th>title</th>
<th>ID</th>
<th></th>
</tr>
</thead>
<tbody id="grouptable">
<%= content_tag_for(:tr, @groups) do |group| %>
<td><%= group.title %></td>
<td><%= group.owner_id %></td>
<td>
<%= link_to 'edit', edit_group_path(:id => group.id), class: "btn btn-primary btn-xs" %>
<%= link_to 'delete', group, remote: true, method: :delete, data: { confirm: 'sure?' },
class: "btn btn-danger btn-xs" %>
</td>
<% end %>
</tbody>
</table>
_table.html.erb
:new_folow
通过API请求检索数据的后台作业。工作完成后,记录的false
字段变为:new_follow
。如何定期刷新此行,直到true
条件为while :new_follow == true do
refresh prepended row every 5 seconds
end
?
换句话说:
override func drawRect(rect: CGRect) {
let width = 200
let height = 300
let boundingBox = CGRectMake(0, 0, CGFloat(width), CGFloat(height))
let context = createBitmapContext(width, height)
let data = CGBitmapContextGetData(context)
let pixels = UnsafeMutablePointer<CUnsignedChar>(data)
var n = 0
for var j = 0; j < height; j++ {
for var i = 0; i < width; i++ {
pixels[n++] = 0 //B
pixels[n++] = 255 //G
pixels[n++] = 0 //R
pixels[n++] = 255 //A
}
}
let image = CGBitmapContextCreateImage(context!)
if let currentContext: CGContext! = UIGraphicsGetCurrentContext() {
UIImagePNGRepresentation(UIImage(CGImage:image!))?.writeToFile("/Users/admin/Desktop/aaaaa.png", atomically: true)
CGContextDrawImage(currentContext, boundingBox, image)
}
}
答案 0 :(得分:0)
在你的js中
var newFollow = true;
var getNewRow = function(){
if(newFollow){
$.ajax({
// ur call here
})
}else{
clearInterval(interval);
}
}
var interval = setInterval("getNewRow",5000);
在你的create.js.erb
中$("#grouptable").prepend('<%= j render(@group)%>');
newFollow = // model.new_follow, this should be true or false;
我希望这会有所帮助。