Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Coffeescript 流星deps不反应_Coffeescript_Meteor - Fatal编程技术网

Coffeescript 流星deps不反应

Coffeescript 流星deps不反应,coffeescript,meteor,Coffeescript,Meteor,我花了好几天的时间试图弄清楚为什么模板没有更新。请帮忙!以下是相关代码 @Listings = new Meteor.Collection 'listings' class Map constructor : (map_canvas=null, map_options=null) -> @listings = Listings.find() @observer = new Deps.Dependency() viewable_listings : ->

我花了好几天的时间试图弄清楚为什么模板没有更新。请帮忙!以下是相关代码

@Listings = new Meteor.Collection 'listings'

class Map
  constructor : (map_canvas=null, map_options=null) ->
    @listings = Listings.find()
    @observer = new Deps.Dependency()

  viewable_listings : ->
    @observer.depend()
    @listings

  set_listings : (listings) ->
    @listings = listings
    @observer.changed()
因此,可查看的_listings()被设置为模板帮助器

Template.listings.helpers
  listings : map.viewable_listings()
但是当更改@listings的值时,模板不会更新。比如说

map.set_listings Listings.find({}, {limit:3})

什么都不做。没有来自列表模板的响应。但是,通过Listings.remove(…)更改数据库中的值会正常工作。

Listings帮助程序不是一个函数,因此依赖项跟踪将无法工作。助手将始终是第一次调用
map.viewable\u listings()
的结果。该值恰好是一个光标,因此有必要渲染某些内容,但不会在需要时进行更新。尝试一下:

Template.listings.helpers
  listings: ->
    map.viewable_listings()

如果将助手更改为
listings:->map.viewable\u listings()
,会发生什么情况?如果这不能解决问题,我建议创建一个。哇,就是这样!!!这是有道理的。显然,将其包装在函数中是使这些助手成为计算的原因。我只是假设整个helper对象是一个计算。再次感谢你,我去看看流星板。请随意张贴您的答案,以便打分。