简体   繁体   中英

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

The jQuery interface makes working with the DOM in JavaScript much simpler. 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:

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. 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. In the JavaScript, you have:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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