我有一个名为person的作用域模型,它有名、姓和全名。我的goQuery使用以下命令:
$scope.person = $goQuery('person', { userName: $scope.person.findme }, { sort: { 'userName': 'asc' }, limit: 1 }).$sync();我遇到的唯一问题是它只填充我正在搜索的字段的值,而不是整个模型。我遗漏了什么?
发布于 2014-05-05 23:37:43
$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及其下面的数据。
发布于 2014-05-16 22:20:23
好的。谢谢你,科林MacDonald。这是如何将结果返回到您的作用域中: 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脚本:
$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;
});
};https://stackoverflow.com/questions/23474302
复制相似问题