繁体   English   中英

绑定模型更改以在EmberJS中查看

[英]Binding model changes to view in EmberJS

我正在尝试为EmberJS实现记录器的接口,这很棒,但是遇到了麻烦。

目前,我有以下代码:

logs.hbs

...
{{input action="search" onEvent="keypress" value=searchText class="search" placeholder="Search"}}
...
<table id="log" class="log">
    <thead>
        <th>Service</th>
        <th>Start Time</th>
        <th>End Time</th>
        <th>URL</th>
        <th>Method</th>
        <th>User</th>
        <th>Response Code</th>
    </thead>
    <tbody>
        {{render "dashboard/logTableLine" model}}
    </tbody>
</table>
...

logTableLine.hbs

{{#each model}}
    {{#link-to "dashboard.log" _id tagName="tr"}}
        <td>{{ServiceID}}</td>
        <td>{{DateString StartTime}}</td>
        <td>{{DateString EndTime}}</td>
        <td>{{URL}}</td>
        <td>{{Method}}</td>
        <td>{{AuthName Auth}}</td>
        <td>{{StatusCode}}</td>
    {{/link-to}}
{{/each}}

和我的app.js

App = Ember.Application.create({
    LOG_TRANSITIONS: true,
    LOG_TRANSITIONS_INTERNAL: true
});

App.Router.map(function(){
    this.resource("dashboard", { path: "/" }, function(){
        this.route("logs", { path: "/logs" });
        this.route("log", { path: "/logs/log/:_id" });
    });
});

App.DashboardLogsRoute = Ember.Route.extend({
    model: function(){
        return Ember.$.getJSON("/logs.json");
    },
    actions: {
        search: function(value){
            if(value != '')
                this.set("content", Ember.$.getJSON("/logs.json?search=" + value));
        }
    }
});

App.DashboardLogRoute = Ember.Route.extend({
    model: function(params){
        return Ember.$.getJSON("/logs/log/" + params._id + ".json");
    }
});

我的问题是将该模型绑定到视图,以便在对服务器的搜索调用之后视图重新呈现。 我想搜索所有数据,不仅要搜索界面中的数据(最近100条记录)。

所以,第一个问题:为什么视图没有更新(绑定)到模型? 第二:是否有更好的方法(最佳实践)?

在此先感谢您的帮助。

现在,您正在实现搜索而无需触发重新路由。 因此,如果用户先搜索然后想要回到搜索之前的页面,那么他们将无能为力。 您要做的是将用户重新路由到同一页面,但传入查询参数。 然后,在模型函数中,您可以查看传入的参数并相应地获取数据。 Ember做到这一点的最新也是最好的方法是query-params功能: http : //emberjs.com/guides/routing/query-params/它已经投入使用了一段时间了,现在处于beta版。 我会尝试一下,因为这是解决此问题的一种非常干净,直观的方法。 祝好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM