簡體   English   中英

具有多個字段的where子句:適用於JavaScript的Arcgis api

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

我正在嘗試執行三個字段的查詢。我有三個組合框,每個組合框都填充有一個字段值。我想查詢從組合框為每個字段選擇的值。我想知道如何在其中收集三個字段條款在哪里? 有什么想法嗎?

<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 = '"...

上面的答案很好。 我想重點介紹一些用於處理此類事情的工具。

jQuery的

jQuery接口使使用JavaScript中的DOM更加簡單。 例如,假設您有一個表單:

<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>

然后,您可以按照以下方式獲取表單中的當前信息,以用於構造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框架允許您聲明性地將DOM元素鏈接到JavaScript變量,因此在DOM中對其進行更改會立即在JavaScript中對其進行更改。 此外,您還可以獲取更改事件,從而可以在需要時重新處理數據。 在此示例中,您可能希望在每次字段更改時查詢數據庫。 方法如下:

<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>

在淘汰賽中,您可以使用'data-bind =“ value:var”'選擇要綁定到DOM元素的變量。 在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

盡管這顯然比jQuery模型要復雜一些,但是它是一個功能強大的工具,因為它允許您在DOM中更新數據時對數據進行反應處理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM