【问题标题】:JSView passing context to deferred objectJSView 将上下文传递给延迟对象
【发布时间】:2018-03-01 22:48:24
【问题描述】:

我尝试在执行函数后将数据上下文传递给延迟对象以修改数据:

function confirmBox(obj){
  var defer = $.Deferred();
  //cut the function
  //if true, it will returned the obj, by false it will be defer.reject()
  defer.resolve(obj);
  return defer.promise();
}

$.link.testTemplate("#main", app)
  .on("click", ".test-item", function(e){
    confirmBox($.view(this)).then(function (answer) {
      console.log(answer.getIndex())
    });
    //console.log($.view(this).getIndex()) => working fine
  })

它返回了一个未定义的值。

我的错误在哪里?

【问题讨论】:

    标签: jquery deferred jsrender


    【解决方案1】:

    如果上下文(视图)不是“项目”视图或在项目视图中,view.getIndex() 将返回 undefined。

    http://www.jsviews.com/#getindex
    http://www.jsviews.com/#viewobject@index

    因此,如果您的 'test-item' 元素不在 {^{for someArray}} 内,则索引将是未定义的。

    当 'test-item' 在项目视图中时,您的示例对我来说很好......

    要不然,能不能把完整的例子发到jsfiddle...

    【讨论】:

      猜你喜欢
      • 2013-05-19
      • 1970-01-01
      • 2012-08-09
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多