将数据发送到parse.com并更新角度$范围 [英] Sending data to parse.com and update angular $scope
问题描述
我将数据发送到parse.com上的Class,我想运行此函数并更新 $ scope
,而无需重新加载视图。
要创建一个 Program
,运行下面的函数可以正常工作,但它有时不会在创建新程序后更新视图,它需要一个页面刷新(当整个函数被调用,如底部所示 - getProgrammes();
<$ p ();
var programmesArray = [];
var QueryProgramme = Parse.Object(); $ p $
getProgrammes = function(){
$ ionicLoading.show (Program);
var query = new Parse.Query(QueryProgramme);
query.equalTo(userId,userId);
query.find( {
success:function(results){
for(var i = 0; i< results.length; i ++){
var object = results [i];
var programmeData = {title:object.get('programmeTitle'),
id:object.id,
练习:object.get('exerciseData')
};
programmesArray.push(programmeData);
}
$ scope.programmes = programmesArray;
$ scope。$ apply();
$ ionicLoading.hide();
},
错误:函数(错误){
alert('您没有任何程序 - 请创建一个');
}
})
};
getProgrammes();
我想我可能会使用 $ scope.apply()
- 因此不可靠。协助使用正确的函数来自动更新 $ scope
会很好。
https://github.com/brandid/parse-angular-patch
基本上我只是引用parse-angular.js文件,然后在我的应用程序中包含依赖项,例如:
angular.module('app',[
'parse-angular',
]);
然后我随时使用Parse查询,并且他们能够正确地使用 $范围
和 $ apply
。该库只是对Parse方法做一些简单的包装,以使异步调用遵守angular的规则。
I am sending data to a Class at parse.com, I would like to run this function and update the $scope
without having to reload the view.
To create a Programme
running the function below works fine, however it sometimes does not update the view following creating a new programme and it requires a page refresh (when the whole function is called as seen at the bottom - getProgrammes();
getProgrammes = function() {
$ionicLoading.show();
var programmesArray = [];
var QueryProgramme = Parse.Object.extend("Programme");
var query = new Parse.Query(QueryProgramme);
query.equalTo("userId", userId);
query.find({
success: function(results) {
for(var i=0; i < results.length; i++) {
var object = results[i];
var programmeData = { title : object.get('programmeTitle'),
id : object.id,
exercises : object.get('exerciseData')
};
programmesArray.push(programmeData);
}
$scope.programmes = programmesArray;
$scope.$apply();
$ionicLoading.hide();
},
error: function(error) {
alert('You do not have any Programmes - please create one');
}
})
};
getProgrammes();
I think I may be hacking this by using $scope.apply()
- therefore making it unreliable. Assistance on the correct function to use in order to automatically update $scope
would be great.
I've been using a library found here:
https://github.com/brandid/parse-angular-patch
Essentially I just reference the parse-angular.js file, and then include the dependency in my app, e.g.:
angular.module('app', [
'parse-angular',
]);
Then I just use Parse queries anytime I like and they participate correctly with $scope
and $apply
. The library just does some simple wrapping on the Parse methods to make the async calls obey the rules of angular.
这篇关于将数据发送到parse.com并更新角度$范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!