简体   繁体   English

具有多个字段的where子句:适用于JavaScript的Arcgis api

[英]where clause with multiple fields : Arcgis api for javascript

I am tring to perform a query with three fields .I have three combobox,each one is populated with a field values.I want to query with the value selected from combobox for each field.I want to know how to gather the three fields in Where Clause? 我正在尝试执行三个字段的查询。我有三个组合框,每个组合框都填充有一个字段值。我想查询从组合框为每个字段选择的值。我想知道如何在其中收集三个字段条款在哪里? any idea please? 有什么想法吗?

<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>

var si = document.getElementById("mySelect").selectedIndex;
var arrayOfOptionsy=document.getElementById("mySelect").options;
//alert("Index: " + arrayOfOptionsy[si].index + " is " + arrayOfOptionsy[si].text);

query.where = "fruit = '" + arrayOfOptionsy[si].text + "' AND not_gis = '"...

The above answer is excellent. 上面的答案很好。 I'd like to highlight a few tools for handling this kind of thing. 我想重点介绍一些用于处理此类事情的工具。

jQuery jQuery的

The jQuery interface makes working with the DOM in JavaScript much simpler. jQuery接口使使用JavaScript中的DOM更加简单。 For example, lets say you had a form: 例如,假设您有一个表单:

<label>Latitude<input id="latitude" type="number" step=".01" min="-90" max="90 /></label>
<label>Longitutde<input id="longitutde" type="number" step=".01" min="-180" max="180" /></label>
<select id="radius">
    <option>1 km</option>
    <option>5 km</option>
    <option>20 km</option>
</select>

You could then grab the current information in the form for use in constructing a where clause as follows: 然后,您可以按照以下方式获取表单中的当前信息,以用于构造where子句,如下所示:

var lat = $('#latitude').val();  // $('#latitude') is the element with id 'latitude'
var lon = $('#longitude').val(); // and .val() grabs the current value of that input
var rad = $('#radius').val();    // and this syntax works with various input elements

Knockout 昏死

The Knockout framework allows you to declaratively link DOM elements to JavaScript variables so changing them in the DOM immediately changes them in the JavaScript. Knockout框架允许您声明性地将DOM元素链接到JavaScript变量,因此在DOM中对其进行更改会立即在JavaScript中对其进行更改。 Also, you are able to grab the change events which allows you to reprocess the data when needed. 此外,您还可以获取更改事件,从而可以在需要时重新处理数据。 In this example, you may want to query the database every time your field changes. 在此示例中,您可能希望在每次字段更改时查询数据库。 Here's how to do it: 方法如下:

<label>Latitude<input data-bind="value: lat" type="number" step=".01" min="-90" max="90 /></label>
<label>Longitutde<input data-bind="value: lon" type="number" step=".01" min="-180" max="180" /></label>
<select data-bind="options: ['1 km', '5 km', '20 km'], value: rad"></select>

In Knockout, you use 'data-bind="value: var"' to select the variable to bind to the DOM element. 在淘汰赛中,您可以使用'data-bind =“ value:var”'选择要绑定到DOM元素的变量。 In the JavaScript, you have: 在JavaScript中,您可以:

var queryModel = {          // we create the "data model" to be used in the DOM
    lat: ko.observable(0),  // and wrap each value in a ko.observable(); we can 
    lon: ko.observable(),   // assign default values or leave them empty
    rad: ko.observable(),
    query: ko.computed(function() {
        // query processing here; to access the variable values use this.lat(),
        // this.lon(), this.rad(); you can then access this variable in JavaScript
        // using queryModel.query()
    }, this)
};

queryModel.query.subscribe(function(query) {
    // this function will be called every time the query variable is recomputed; you
    // may add code here that would run this query every time the query updates
});

ko.bind('queryModel'); // and finally, we "bind" the data model to the DOM

Though this is obviously a little more complicated than the jQuery model, it is a powerful tool since it allows you to reactively process the data as it is updated in the DOM. 尽管这显然比jQuery模型要复杂一些,但是它是一个功能强大的工具,因为它允许您在DOM中更新数据时对数据进行反应处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM