没有方法'有'

fan*_*ncy 2 javascript client-side backbone.js

模型的属性......

attributes: Object
    array: Array[1]
    id: "ef93fcc0d431d1000003"
    state: "new"
Run Code Online (Sandbox Code Playgroud)

我正在设置......我唯一的区别是为数组添加了另一个值.

model =
    array: Array[2]
    id: "ef93fcc0d431d1000003"
    state: "new"
    __proto__: Object
Run Code Online (Sandbox Code Playgroud)

我像这样扩充数组......

new_array = model.get('array').slice()
new_array.push new_value
model.set({array: new_array})
Run Code Online (Sandbox Code Playgroud)

完全错误......

Object function (obj) { return new wrapper(obj); } has no method 'has'
Run Code Online (Sandbox Code Playgroud)

这是Backbone.js引发它的一点......

  // Update attributes.
  for (attr in attrs) {
    val = attrs[attr];
    if (!_.isEqual(now[attr], val)) delete escaped[attr];
    options.unset ? delete now[attr] : now[attr] = val;
    delete this._changed[attr];
    if (!_.isEqual(prev[attr], val) || (_.has(now, attr) != _.has(prev, attr))) {
        Uncaught TypeError: Object function (obj) { return new wrapper(obj); } has no method 'has'
      this._changed[attr] = val;
    }
  }
Run Code Online (Sandbox Code Playgroud)

这是从服务器发送的更新.

只是寻找一些想法或方向来找出会导致这个错误的原因.

谢谢!

Juh*_*nen 6

看起来您的代码引用了Underscore.js.也许这不见了?

  • 哦,我明白了,真棒,我将骨干更新为0.9并忘记更新下划线.更新解决了问题!谢谢! (4认同)