在Dojo中如何迭代一个对象(关联数组)? [英] How can you iterate over an object (associative array) in Dojo?

查看:118
本文介绍了在Dojo中如何迭代一个对象(关联数组)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dojo是否有一个类似于jQuery的 each()的方法,允许您传递一个对象进行迭代? jQuery.each()允许您传递数组或对象。在后一种情况下,回调函数同时接收一个键和该值。有什么可以让你在Dojo中做到这一点吗?

Does Dojo have a method similar to jQuery's each() that allows you to pass an object to iterate over? jQuery.each() allows you to pass either an array or an object. In the latter case, the callback function receives both a key and the value. Is there something that allows you to do this in Dojo?

推荐答案

看起来你正在寻找 dojox .lang.functional.object.forIn

dojo引用中没有实际的文档页面,只是文章使用Dojo的JavaScript功能乐趣

There's no actual documentation page in dojo reference, only a small example in article Functional fun in JavaScript with Dojo:


模块dojox.lang.functional.object定义重要的对象助手:

Module dojox.lang.functional.object defines important object helpers:

df.forIn(object, callback[, thisObject])




If you have something against using that module you can also easily make your own variant:

function objEach(obj, f, scope){
    for(var key in obj){
        if(obj.hasOwnProperty(key)){
            f.call(scope, obj[key], key);
        }
    }
}

对于数组,已经有dojo .forEach()在基础库中。

For arrays there is already dojo.forEach() in the base library.

这篇关于在Dojo中如何迭代一个对象(关联数组)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆