0

我正在开发一个在线/离线应用程序,我注意到了这一点:

我从 localStorage 中获取我的离线检索。(每次用户在线登录时,我都会使用从我的服务器检索到的附加数据来保存他)

如果同一个用户现在尝试离线登录,我会检查此运算符是否与我的集合中的任何运算符匹配,如果它与条目匹配,则返回运算符匹配项。

问题是,我从 collection.get(#id) 获得的运算符没有来自骨干运算符模型的任何方法。

在更正我的代码之前是这样的:

if( this.isLocalValidOperator( operator ) ){
  var operatorMatch = this.get(operator.get('id'));
  cb( operatorMatch );
}

我的更正,现在可以了

if( this.isLocalValidOperator( operator ) ){
  var operatorMatch = this.get(operator.get('id'));
  // must add additional attributes from the match, then return the operator created with new Operator( someAttributes )
  operator.set({ 
    isSuperadmin: operatorMatch.get('isSuperadmin'),
    isModerator: operatorMatch.get('isModerator'),
    firstname: operatorMatch.get('firstname'),
    lastname: operatorMatch.get('lastname')
  });
  cb( operator );
}

我究竟做错了什么 ?

4

1 回答 1

0

如果其他人遇到这个或类似的丢失方法的问题......我在从 localStorage 恢复时丢失了方法,但属性数据仍然存在。问题是在集合中我缺少该属性:

model: ModelName

在我包含它之后,方法在页面重新加载时保持不变。

于 2013-12-17T03:07:08.553 回答