gpt4 book ai didi

javascript - 使用来自多个文本框的输入形成一系列地址列表

转载 作者:行者123 更新时间:2023-11-28 18:32:23 25 4
gpt4 key购买 nike

我正在构建一个结构化地址序列,用于在 Google map 中进行搜索。我在所有文本框中添加了 ng-change 来收集数据。地址如下..

  1. 地址行1
  2. 地址行2
  3. 面积
  4. 城市
  5. 国家

因此,当用户开始在任何字段中输入时,地址应将自身构造为 ..

例如:“地址行1,地址行2,区域,城市,国家”

HTML:

  <div class="row">
<label class="label"> Address Line1</label>
<input type="text" name="addressline1" ng-change="getAddress(address)" ng-model="address.line1"/>

<label class="label"> Address Line1</label>
<input type="text" name="addressline2" ng-change="getAddress(address)" ng-model="address.line2"/>

<label class="label"> Area</label>
<input type="text" name="area" ng-change="getAddress(address)" ng-model="address.area"/>

<label class="label"> City</label>
<input type="text" name="city" ng-change="getAddress(address)" ng-model="address.city"/>

<label class="label"> State</label>
<input type="text" name="state" ng-change="getAddress(address)" ng-model="address.state"/>

<label class="label">Country</label>
<input type="text" name="country" ng-change="getAddress(address)" ng-model="address.country"/>
</div>
<div class="row">{{enteredAddress}}<?div>

Controller :

 $scope.getAddresss=function (address) {
if (address.addressLine1) {
address = address.concat(',' + address.addressLine1);
} else {
address = address.addressLine1;
}
if (address.addressLine2) {
address = address.concat(',' + address.addressLine2);
} else {
address = address.addressLine2;
}
if (address.area) {
address = address.concat(',' + address.area);
} else {
address = address.area;
}
if (address.city) {
address = address.concat(',' + address.city);
} else {
address = address.city;
}
if (address.state) {
address = address.concat(',' + address.state);
} else {
address = address.state;
}
$scope.enteredAddress=address;
}

但是这个逻辑在多种情况下都会失败。谢谢

最佳答案

$scope.getAddresss = function(address) {

var add1, add2, area, city, state, country;

if (address.addressLine1) {
add1 = address.addressLine1 + ', ';
}
if (address.addressLine2) {
add2 = address.addressLine2 + ', ';
}
if (address.area) {
area = address.area + ', ';
}
if (address.city) {
city = address.city + ', ';
}
if (address.state) {
state = address.state + ', ';
}

$scope.enteredAddress = add1 + add2 + area + city + state + country;
}

关于javascript - 使用来自多个文本框的输入形成一系列地址列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37741234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com