Javascript ng资源查询返回所有记录
我有这样的ng资源设置Javascript ng资源查询返回所有记录,javascript,angularjs,angularjs-ng-repeat,odata,Javascript,Angularjs,Angularjs Ng Repeat,Odata,我有这样的ng资源设置 (function () { 'use strict'; var storeCommandServiceRoot = '/api/StoreCommandsRest/:id'; angular.module('common.service') .factory("storeCommandResource", ["$resource", "appSettings", storeCommandResource]) function storeCommandResource(
(function () {
'use strict';
var storeCommandServiceRoot = '/api/StoreCommandsRest/:id';
angular.module('common.service')
.factory("storeCommandResource", ["$resource", "appSettings", storeCommandResource])
function storeCommandResource($resource, appSettings) {
return $resource(appSettings.serverPath + storeCommandServiceRoot, { id: '@id' },
{ "update": { method: "PUT" } });
}}());
我试图通过查询一个名为“Serial”的整数属性来获取记录
function getStoreCommandsBySerial() {
var storeCommandGet = storeCommandResource.get({ Serial: 3 });
storeCommandGet.$promise.then(function (response) {
debugger;
});
}
但作为回应,我得到了所有的记录。我只希望是Serial=3的记录。
发送过来的url看起来像
在服务器端,它是一个oDataController,具有基于REST的功能 似乎您的名称与参数不一致。在工厂中,您有
{id:'@id'}
,但在控制器中,您使用:storeCommandResource.get({Serial:3})代码>
尝试更改storeCommandResource.get({Serial:3})
tostoreCommandResource.get({id:3})代码>
此外,您的storeCommandServiceRoot应该是“/api/StoreCommandsRest/?id=:id”
如果您打算在url中保留“序列号”,请确保将其余的更改为“序列号”,而不是id和序列号混合