小编Rhy*_*hys的帖子

Python全局变量不更新

我是Python和编程的新手,但似乎无法理解为什么这个函数不更新全局变量

global weight
weight = 'value'
def GetLiveWeight():
    SetPort()
    while interupt == False:
        port.write(requestChar2)
        liveRaw = port.read(9)
        liveRaw += port.read(port.inWaiting())
        time.sleep(0.2)
        weight = liveRaw.translate(None, string.letters)
    return weight
Run Code Online (Sandbox Code Playgroud)

我也尝试过这个

weight = 'value'
def GetLiveWeight():
    global weight
    SetPort()
    while interupt == False:
        port.write(requestChar2)
        liveRaw = port.read(9)
        liveRaw += port.read(port.inWaiting())
        time.sleep(0.2)
        weight = liveRaw.translate(None, string.letters)
    return weight

try:
    threading.Thread(target = GetLiveWeight).start()
    print liveWeight
except:
    print "Error: unable to start thread"
Run Code Online (Sandbox Code Playgroud)

python

9
推荐指数
1
解决办法
1万
查看次数

Rails:在Bootstrap模式中编辑记录

我正在尝试在Rails中使用Bootstrap模式来编辑记录,但我无法将模式范围扩展到当前记录

静态链接是

<%= link_to "Weigh Out", edit_ticket_path(ticket), "data-toggle" => "modal", :class => 'btn btn-mini', :id => 'edit_modal_link', "data-toggle" => "modal" %>
Run Code Online (Sandbox Code Playgroud)

我真的需要在id/edit上调用模态,这是票号,但是无法将其链接到表中的选定记录.

有任何想法吗?

或渲染部分,但必须使用可用的故障单调用部分,它是否正确定位到我们需要编辑的故障单?

我的部分看起来像

<%= form_for @ticket, :html => { :class => 'form-horizontal' } do |f|%>    
  <div class="control-group">
    <%= f.label :customer_name, :class => 'control-label' %>
    <div class="controls">
      <%= f.hidden_field :customer_id, :class => 'text_field', :id =>"cust_id" %>
      <%= f.autocomplete_field :customer_name, autocomplete_customer_name_customers_path, :id_element => '#cust_id', :class => 'text_field ui-autocomplete-input' %>
    </div>
Run Code Online (Sandbox Code Playgroud)

哪个需要在Modal中渲染,

ruby-on-rails modal-dialog twitter-bootstrap

7
推荐指数
2
解决办法
8562
查看次数