Javascript 在AngularJS中回调之前如何启动
这是我的一段代码:Javascript 在AngularJS中回调之前如何启动,javascript,angularjs,Javascript,Angularjs,这是我的一段代码: .factory('Latest', function(EBSheadless) { return { posts: function() { // Call the API, and define the specific endpoint return EBSheadlessDrupalAPI.loadEndpoint('views/news.json'); }, post: function(posts,id,call
.factory('Latest', function(EBSheadless) {
return {
posts: function() {
// Call the API, and define the specific endpoint
return EBSheadlessDrupalAPI.loadEndpoint('views/news.json');
},
post: function(posts,id,callback){
var findpost = {};
for(var i=0;i<posts.length;i++) {
findpost[posts[i].nid] = posts[i];
}
callback(findpost[id]);
}
};
})
但我需要这样的链接(我无法编辑后端):
因此,我必须在回调中添加/
。我尝试了很多职位,但都不起作用。
我怎样才能解决它?谢谢 为什么不像这样连接字符串
回调(“/”+findpost[id])
。这将返回/This-is-a-news
post: function(posts,id,callback){
var findpost = {};
for(var i=0;i<posts.length;i++) {
findpost[posts[i].nid] = posts[i];
}
callback("/"+findpost[id]);
}
post:function(posts、id、回调){
var findpost={};
对于(var i=0;i
/this-is-a-news
post: function(posts,id,callback){
var findpost = {};
for(var i=0;i<posts.length;i++) {
findpost[posts[i].nid] = posts[i];
}
callback("/"+findpost[id]);
}