【问题标题】:How to display variable value in coffeescript如何在咖啡脚本中显示变量值
【发布时间】:2014-10-15 04:00:45
【问题描述】:
jQuery ->
  test = path
  if $('#spot-index-sortable').length > 0

    $('#spot-index-sortable').sortable(

      axis: 'y'
      items: '.item'
      cursor: 'move'

      sort: (e, ui) ->
        ui.item.addClass('active-item-shadow')
      stop: (e, ui) ->
        ui.item.removeClass('active-item-shadow')
        # highlight the row on drop to indicate an update
        ui.item.children('td').effect('highlight', {}, 1000)
      update: (e, ui) ->
        item_id = ui.item.data('item-id')
        console.log(item_id)
        position = ui.item.index() # this will not work with paginated items, as the index is zero on every page
        $.ajax(
          type: 'POST',
          url: test+'admin/spot_categories/update_row_order',
          dataType: 'json',
          data: { category: {category_id: item_id, row_order_position: position } }
        )
    )

变量 test 将有一个来自 javascript 的值,然后我想在 $.ajax(url:test) 处连接上面的测试变量值。如何做到这一点

【问题讨论】:

  • 什么是path?这是在哪里定义的?

标签: coffeescript


【解决方案1】:

试试这个:注意双引号

url: "#{test}/admin/spot_categories/update_row_order",

【讨论】:

  • 这与他做过所做的没什么不同。真正的问题是……path 值从何而来?
  • 你怎么看?他的问题对我来说非常具有声明性“我如何显示变量”......他显示了一个字符串。对我来说,那尖叫插值。 Coffeescript 编译成 js,你知道的。他的代码没有这样做,他正在做传统的 js concat ......他问“你是如何在咖啡脚本中做到的”,而不是“我的路径未定义”......等等......或者“我收到'这个'错误而且我不知道它是什么..”。
  • 我认为他的意思是 test 在此函数的范围之外声明,所以可能是window.test?很难用“来自 javascript 的值”作为描述来了解。
  • 我的意思是在coffeescript中:test + "/admin/stuff"是相同的,并且编译成完全相同的javascript,如:"#{test}/admin/stuff"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-05
  • 1970-01-01
  • 2013-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-13
相关资源
最近更新 更多