Backbone coffeescript行为 - 数据无论如何都会忽略所有IF语句和传递

时间:2014-07-26 13:47:04

标签: ruby-on-rails backbone.js coffeescript

我的网站上有一个神秘的行为..我的数据忽略了所有的IF语句并传递了它的所有要求' nt。我确定我没有类似的功能,这是唯一的功能。但数据传输就像50 /秒(PUT到DB),它是我的第一个如此大的网站,这个问题我无法解决。我甚至尝试过在调用之后没有定义found_item,它仍会创建空对象。

// my View

  ....# 600 lines of code
  found_item = []
  get_items_from_killed_monster: ->
    item = []
    item[1] = itemname: "medicine1"
    ....
    item[110] = itemname: "weapon"
    drop_random_number = randomInt(1,10)
    if drop_random_number > 5
      found_item = item[1]
    else
      found_item = item[110]
    if found_item.itemname is "medicine1"
      @model.set(medicine1: @model.attributes.medicine1+1)
      @model.save()    ## its working, im getting that medicine
    if found_item.itemname is "weapon"
      router.send_item_to_inventory(found_item)  ##sending it to Router



// My Router
  send_item_to_inventory: (attributes) ->
    if attributes.itemname is "weapon"
      @view = new Sprint.Views.Inventories.IndexView(inventories: @inventories)
      @view.create_item(attributes)
      console.log(attributes)
      ## console says: Object {itemname: "medicine1"}
      ## it passed somehow !

// My Inventories.indexview
  create_item: (attributes) ->
    if attributes.itemname is "weapon"
      this.collection = new Sprint.Collections.InventoriesCollection
      this.model = new this.collection.model(item: attributes.name)
      this.collection.create(this.model.toJSON())
      console.log(attributes)
      ## console says: Object {itemname: "medicine1"}
      ## it passed somehow ! The object is created with itemname: "medicine1"

0 个答案:

没有答案