附加参数以包含数据请求?

时间:2014-07-16 18:38:59

标签: javascript ember.js ember-data

我的代码在某一点上运行这一行:

var searchData = that.store.find("searchResult",{key: searchKey});

基本上,我正在尝试获取模型searchResult的所有实例。

我的型号代码如下:

App.SearchResult = DS.Model.extend({
    searchResultID: DS.attr('number'),
    entityID: DS.attr('number'),
    entityTypeID: DS.attr('number'),
    entityType: DS.attr('string'),
    searchText: DS.attr('string'),

});

对于客户端的searcHRestult来说,这几乎就是我的全部内容。

在服务器端,我处理对/ searchResults路由的GET请求。

  this.resource('searchResults', {path: '/searchResults'});

以上内容已添加到Ember Router。

然而,我将要求通过此路由传递参数{criteria:“user location”}。我的想法是,在服务器端,我的代码将搜索此条件参数,然后根据需要的标准运行sql。 (即,如果标准=“用户位置”,则代码将运行与“用户”和“位置”相关的sql)。

但是,在服务器端,当我检查request.params的值时,该值显示为[]。

所以当我这样做时:

var searchData = that.store.find("searchResult",{criteria: "user location"});

标准参数从不显示服务器端。即使我在这里发布的第一行代码,searchKey也从不显示服务器端。

我在这里遗漏了什么吗?我是否必须做任何事情来启用参数传递到服务器端?

(我使用node.js作为服务器)。

1 个答案:

答案 0 :(得分:0)

道歉,经过一个小时的测试,似乎参数被传递,并且可以访问它。不幸的是,我的测试代码被放置了。

所以正确的方法肯定是:

that.store.find("searchResult",{key: value})

其中'key'是您要传递的参数,value是您要传递给服务器端的参数的值。

您必须通过

访问这些参数
request.query.key