English 中文(简体)
Java处的财产搜查
原标题:Property based searches in Javascript

在寻找最佳办法搜索 Java稿中的一系列物体(单体字似乎是一种迭加功能)的同时,我来了,这一职位“上”似乎确实是这样做的leg。

但 我有一些问题:

  1. Javascript doesn t have associative arrays. These seems like one. What gives?
  2. This seems like a very elegant solution but how does it stack up against the competition?

另外,你将如何从日本宇宙航空研究开发机构接手,并建立一个结构类似的阵列? 大多数辅导员手脚,并推出实例,以显示阵列的关联性,但无法实际使用。

使用这种方法是否有任何陷阱?

以下链接将受到欢迎(beyond this)。

感谢。

UPDATE: This is what I am having trouble with. If I have data coming back from the server similar to this:

$.getJSON("map.php?jsoncallback=?", function(data) {
    for (var x=0,xx=data.stars.length; x<xx; x++) {
        stars.push( 
            new Star(
                data.stars[x].id,
                data.stars[x].xpos, data.stars[x].ypos,
                data.stars[x].name, data.stars[x].owner
            )
        );
    }
});

在星号为一类的情况下:

function Star(id, x, y, n, o) {
    this.id = id;
    this.x = x; this.y = y;
    this.name = n;  this.owner = o;
}

www.un.org/Depts/DGACM/index_spanish.htm 因此,我如何把它变成“联系”风格阵列?

最佳回答

Java 射线物体应使用数字序列指数,但你可以使用简单的物体,这些物体只是收集的关键/数值。

在你联系的法典中,该功能位于阵列内的一个物体。

请注意,该法典将Query列为扶养(使用$.grep)。

关于业绩,我建议你使用标准>。 现代浏览器提供了native implementations,即really temp/strong>,与习俗执行相比。

对于兼容性(主要是国际电子计算方法),你可以包括上述链接的方法执行。

这种方法确实容易使用,现在成为ECMA 5th Edition specification(PDF)(,第15.4.20):

var filtered = existingArray.filter(function (obj) {
  return obj.property == someValue;
});

上述代码将给你一个新的过滤阵列,其所有物体均与<代码>filter<> 代码>背靠功能中规定的条件相符。

问题回答

在 Java,所有物体都是收集姓名价值乳制品。 如果你想通过收集物体的特性来加以修复,请看该守则:

for (var key in object) {
    alert(key +  :  + object[key]);
}

如果你想抹去继承的财产:

for(var key in object) {
    if (object.hasOwnProperty(key)) {
        alert(key +  :  + object[key]);
    }
}

如果对电子计算机兼容性没有规定,你可以使用以下代码添加过滤指挥:

if (!new Array().filter) Array.prototype.filter = function (fnCallback) {
  var ret = new Array();
  var j = 0;
  for (var obj in this)
    if (fnCallback(obj)) ret[j++] = obj;
  return obj;
};




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.