gpt4 book ai didi

ember.js - 查找路由和 Controller 的查询概念

转载 作者:行者123 更新时间:2023-12-02 04:58:38 25 4
gpt4 key购买 nike

我的问题有点笼统。在 ember 中使用 findQuery 的路由和 Controller 的最佳概念是什么。

我有数据过滤的 api。数据请求由执行

this.store.findQuery('dataModel', {"q": JSON.stringify({"filters": filters})});

之后我在表格 View 中显示它们。过滤器由模板中的表单 View 更新。

我目前的解决方案:
表单 View 设置 Controller 参数和来自 Controller 的按钮调用 Action 。 Controller Action 加载参数,执行 findQueryset('content',data) .

在大多数情况下,我看到了带有定义 model: function() 的概念。 ..在路线和 setupController: function(controller, model)controller.set('content',model) .我喜欢这个“集合”,因为“内容”是 RecordArray(不是 PromiseArray),我可以轻松地将它用于数据表和其他 JavaScript 插件。我认为我的解决方案不好。

最佳答案

我认为您的概念是正确的,我一直在使用以下流程:

在您的路由器中:

App.Router.map(function() {
this.resource('search', { path: '/query/:filters' });
});
App.SearchRoute = Ember.Route.extend({
model: function(params) {
return this.store.findQuery('dataModel', {"q": JSON.stringify({"filters": params.filters})});
});

在您的 html 中,只需绑定(bind)将导致新搜索路线的操作,
如下所示:
<button {{action "doSearch"}}>Search</button>

在您的 Controller 中:
App.SearchController = Ember.ArrayController.extend({
...
actions: {
doSearch: function() {
var query = buildYourQueryObject();
this.transitionToRoute("search", query);
}
}

单击按钮后,应用程序将转换到您的搜索路径,“查询”将被序列化并发送到 Route,并且 Route.model() 将尝试根据提供的序列化参数填充。

注意:代码已被简化,您可能需要添加更多内容才能使其正常工作

关于ember.js - 查找路由和 Controller 的查询概念,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19111022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com