我有一个名为person的范围模型,它具有firstname,lastname和fullname。我的goQuery适用于此:
$scope.person = $goQuery('person', { userName: $scope.person.findme }, { sort: { 'userName': 'asc' }, limit: 1 }).$sync();
我遇到的唯一问题是它只填充我搜索的字段的值,而不是整个模型。我错过了什么?
答案 0 :(得分:1)
$ scope.person.findme抛出错误,因为尚未定义$ scope.person。我不确定这是怎么回事。
这是一个有效的例子:
$scope.person = $goQuery('person', 'person', { userName: 'user1' }, { sort: { 'userName': 'asc' }, limit: 1 }).$sync();
$scope.person.$add({ userName: 'user1', fname: 'a', lname: 'b'});
$scope.person.$add({ userName: 'user2', fname: 'c', lname: 'd'});
$scope.person.$add({ userName: 'user3', fname: 'e', lname: 'f'});
window.person = $scope.person;
如果您在window.person上查看模型,您应该会看到user1的ID及其数据。
答案 1 :(得分:0)
确定。谢谢科林麦克唐纳。这是将结果返回到您的范围的方法: HTML代码:
<label>Find User:</label>
<input type="text" ng-model="person.findme" placeholder="Enter Full Name to Search..." />
<input type="button" id="Find" value="Search" ng-click="Find()" />
JAVA SCRIPT:
$scope.Find = function () {
console.log('entering find method...')
$scope.person = $goQuery('person', { userName: $scope.person.findme }, { limit: 1 }).$sync();
$scope.person.$on('ready', function () {
var id = $scope.person.$$index[0];
if (!id) {
// no results found
return;
}
$scope.person = $scope.person[id];
$scope.person.id = id;
});
};