Javascript EmberData RESTAdapter,使用url筛选器在一个页面上定期刷新
我有一个主机模型,目前非常简单:Javascript EmberData RESTAdapter,使用url筛选器在一个页面上定期刷新,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,我有一个主机模型,目前非常简单: App.Host = DS.Model.extend name: DS.attr 'string' 数据适配器由ember data处理,我的路由如下所示: App.HostsRoute = Ember.Route.extend init: -> @_super() @refresh() model: -> @store.find 'host', problematic: 1 refresh:
App.Host = DS.Model.extend
name: DS.attr 'string'
数据适配器由ember data处理,我的路由如下所示:
App.HostsRoute = Ember.Route.extend
init: ->
@_super()
@refresh()
model: ->
@store.find 'host',
problematic: 1
refresh: ->
setTimeout =>
@store.find('host', { problematic: 1 }).then (hosts) =>
@controller.set 'content', hosts
@refresh()
, 10000
我的模板将显示用于列出和管理nagios警报的框列表:
<h2>Hosts list</h2>
<div class="row">
<div class="col-md-8">
{{#each host in controller}}
<div class="box box-solid box-default collapsed-box">
<div class="box-header">
<h5 class="box-title">
<i class="fa fa-server"></i>
{{ host.name }}
</h5>
<div class="box-tools pull-right">
<button class="btn btn-default btn-sm" data-widget="collapse"><i class="fa fa-plus"></i></button>
</div>
</div>
<div class="box-body no-padding table-responsive" style="display: none">
{{#link-to 'host' host}}{{host.name}}{{/link-to}}
<table class="table table-hover">
<colgroup>
<col/>
<col style="width: 100%"/>
<col/>
<col/>
</colgroup>
<thead>
<tr>
<th>Service</th>
<th>Message</th>
<th>State</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
{{/each}}
</div>
<div class="col-md-4">
{{outlet}}
</div>
</div>
但同样的问题,什么也不改变
我完全不知道为什么这不适用于过滤器或查询参数…您应该设置模型,而不是内容当您的模型更改时,ember必须为其生成新的html。即将到来的微光更改将阻止html完全刷新,但在此之前,手动更改的任何DOM状态都需要能够处理底层内容的更改。如何设置模型而不是内容?请给我一些行代码示例?是的,我可以理解DOM重写的概念,但是您能解释一下为什么在rest ajax调用中没有查询参数时,这种方法可以完美地工作吗?问题=1。谢谢。要设置模型'refresh:->setTimeout=>@store.find'host',{problemblem:1}。然后hosts=>@controller.set'model',hosts@refresh,10000`那么就用'model'替换'content'吗?我测试过,结果完全一样。我错过了什么?“模型”和“内容”之间有什么区别?
model: ->
@store.filter 'host', {}, (host) ->
host.get 'problematic'
.then (hosts) ->
hosts
refresh: ->
setTimeout =>
@store.filter 'host', {}, (host) ->
host.get 'problematic'
.then (hosts) =>
@controller.set 'content', hosts
@refresh()
, 10000