我的单页应用程序加载主页,我想显示一系列想法.每个想法都显示在一个动画flash容器中,动画显示在想法之间循环.
想法使用$ http加载:
$scope.flash = new FlashInterface scope:$scope,location:$location
$http.get("/competition.json")
.success (data) ->
$scope.flash._init data
Run Code Online (Sandbox Code Playgroud)
但是,要从历史导航和UX中受益,我希望更新地址栏以使用$ location显示每个想法的正确URL:
$location.path "/i/#{idea.code}"
$scope.$apply()
Run Code Online (Sandbox Code Playgroud)
我在这里调用$ apply,因为这个事件来自AngularJS上下文,即Flash.我希望保留当前的控制器/视图,并使视图不重新加载.这非常糟糕,因为重新加载视图会导致整个flash对象被抛弃并且预加载器循环再次开始.
我试过听$ routeChangeStart来做一个preventDefault:
$scope.$on "$routeChangeStart", (ev,next,current) ->
ev.preventDefault()
$scope.$on "$routeChangeSuccess", (ev,current) ->
ev.preventDefault()
Run Code Online (Sandbox Code Playgroud)
但无济于事.如果我在改变$ location.path时想出一种覆盖视图重载的方法,那么整个事情就会变得很糟糕.
我仍然非常感觉AngularJS,所以我很高兴有关如何构建应用程序以实现我的目标的任何指示!
根据旧谷歌集团的这个帖子,Apps脚本基于ECMA-262第3版.
这似乎得到了编辑器中的自动完成显示第3版阵列功能这一事实的支持.
但是,以下代码运行得非常好,这使人对此事表示怀疑:
var array = [
1,2,3,4,5
];
Logger.log("forEach:");
array.forEach(function (item,idx,arr) {
Logger.log(item);
});
Run Code Online (Sandbox Code Playgroud)
请注意每个使用ECMA-262第5版阵列功能.
有权威的人会给出明确的答案吗?为什么会这样?是否可以安全地依赖所有第5版功能或已经实施并且似乎有效的子集?
要明确这个问题涉及从数据库加载数据,而不是更新数据库中的文档.
使用以下架构:
new mongoose.Schema
name: String
code:
type: String
index:
unique: true
_contacts: [
type: mongoose.Schema.Types.ObjectId
ref: 'Person'
]
Run Code Online (Sandbox Code Playgroud)
我已经创建了我的文档:
client = new Client code:'test',name:'test competition',contacts:[]
client.save()
Run Code Online (Sandbox Code Playgroud)
在应用程序的其他地方或通过API调用,它无法轻易引用上面缓存的版本:
Client.findOne(code:'test').exec (err,client) ->
return if err or not client
client._contacts.push person.id # person has come from somewhere
client.save (err) ->
return err if err
Run Code Online (Sandbox Code Playgroud)
如果我们返回到我们原始的客户端对象,我想知道的是,是否有办法为整个文档或只是特定路径刷新该对象.例如;
client.refresh '_contacts', (err) ->
return err if err
Run Code Online (Sandbox Code Playgroud)
或者更好的做法是只维护一个全局引用的对象?