直感的なピクセルからの回答に基づいて、次の解決策を思いつきました。
次の URL を作成します:
http://somedomain.com/#/searchresults/?lastname=king&firstname=stephen&city=somecity
この URL の構成方法については、ここでは説明しません。私の場合、フォームといくつかのイベント ハンドラーを含む独自のビューを使用します。
動作するようになったコードは次のようになります。
App.Router.map(function() {
this.resource("searchresults", { path: '/searchresults/:dynamic' });
});
App.SearchresultsRoute = Ember.Route.extend((function() {
var deserializeQueryString = function (queryString) {
if(queryString.charAt(0) === "?")
queryString = queryString.substr(1);
var vars = queryString.split('&'),
i = 0, length = vars.length,
outputObj = {};
for (; i < length; i++) {
var pair = vars[i].split('=');
outputObj[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
return outputObj;
};
return {
model: function(param) {
var paramObj = deserializeQueryString(param.dynamic);
return App.Searchresult.find(paramObj);
}
};
})()
);
App.Store = DS.Store.extend({
revision: 12,
adapter: DS.RESTAdapter.create({
namespace: 'api'
})
});
App.Searchresult = DS.Model.extend({
lastname: DS.attr('string'),
firstname: DS.attr('string'),
street: DS.attr('string'),
hno: DS.attr('string'),
zip: DS.attr('string'),
city: DS.attr('string'),
country: DS.attr('string'),
birthdate: DS.attr('string')
});
これにより、REST API への HTTP GET 要求が生成されます。
http://somedomain.com/api/searchresults?lastname=king&firstname=stephen&city=somecity
私の REST API は次のように応答します。
{"searchresults":
[{"id":"2367507","lastname":"King","firstname":"Stephen","street":"Mainstreet.","hno":"21" ...},
{"id":"3222409","lastname":"King","firstname":"Stephen","street":"Broadway","hno":"35" ...}
]}
そして、これはこのテンプレートで視覚化されます:
<h2>Searchresults</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Street / Hno</th>
<th>City</th>
<th>Birthyear</th>
</tr>
</thead>
<tbody>
{{#each item in controller}}
<tr>
<td>{{item.firstname}} {{item.lastname}}</td>
<td>{{item.street}} {{item.hno}}</td>
<td>{{item.zip}} {{item.city}}</td>
<td>{{item.birthdate}}</td>
</tr>
{{/each}}
</tbody>
</table>
カスタムデシリアライザーを使用する必要のない、よりエレガントな方法を誰かが見つけた場合は、喜んでソリューションを更新します。http://somedomain.com/#/searchresults/king/stephen/somecityを示唆する (他の) ダニエルによって提供された回答は、私の場合には部分的ではありません。基準/フィルター。ユーザーは通常、それらのいくつかを埋めることを選択します。
この例は、ember-data リビジョン: 12 および Ember 1.0.0-RC.3 に基づいています。