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