我刚开始接触 Dojo,我对所有模块的数量和质量印象深刻。然而,来自 AngularJS,我发现 Dojo's MVC 的双向数据绑定(bind)有点欠缺。
真的没有办法订阅 Dojo 对象存储,在模板中有一个循环来迭代存储中的项目,并在添加/删除项目时自动更新 View 吗? example tutorial使用 dojo/store/Observable
实现这个繁琐的逻辑:
results.observe(function(item, removedIndex, insertedIndex){
// this will be called any time a item is added, removed, and updated
if(removedIndex > -1){
removeRow(removedIndex);
}
if(insertedIndex > -1){
insertRow(item, insertedIndex);
}
}, true);
function insertRow(item, i){ ... }
function removeRow(i){ ... }
在 AngularJS 中,你会做这样的事情:
<li ng-repeat="item in results">
<span>{{item.text}}</span>
</li>
那么我是否必须在 Dojo 广泛的小部件和模块集合和 AngularJS 的具有双向数据绑定(bind)的直接模板之间做出选择?
最佳答案
首先恭喜你来到道场这边。 是的,AngularJS 对于 2 路数据绑定(bind)非常方便,但您很快就会发现,随着应用程序变得越来越复杂,您将需要强大(且数量众多)的 Dojo/Dijit/Dojox 模块的帮助。
你是对的 dojo/Observable 目前通过 Dojo 中的 store 提供绑定(bind)。它确实可以实现与 AngularJS 相同的功能。结帐dgrid examples演示。
为方便起见,我们制作了一个模块,用于以类似于 Angular JS 的格式进行绑定(bind)。它叫 dbind .它目前可以独立使用,很快就会集成到Dojo的核心中。您还应该检查 dojox/mvc/Bind
关于angularjs - Dojo:带数据绑定(bind)的循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18801645/