다음 양식 필드가 있습니다. 사용자가 임의의 주소 필드를 변경할 때마다 모든 양식 필드의 연결된 문자열 인 longaddress 필드를 업데이트하려고합니다. 다음과 같이 longaddress가 구글 맵 자동 완성으로 전달되기 때문에 나는이 도시와 국가 필드에 대한 몇 가지 위생을 필요로JQuery On Change 이벤트 함수
<input id="address1" type="text" value="" name="address1" >
<input id="address2" type="text" value="" name="address2" >
<input id="city" type="text" value="" name="city" >
<input id="state" type="text" value="" name="state" >
<input id="postcode" type="text" value="" name="postcode" >
<input id="country" type="text" value="" name="country" >
<input id="longaddress" type="text" value="" name="longaddress" >
은 현재 내가 백본을 사용하여 위를 달성하기 위해 필드를 바인딩 :
initialize: function() {
c.bindAll(this, "updateLongAddress"), this.on({
"change:address1 change:address2 change:postcode change:country": this.updateLongAddress,
"change:city": this.removeUnwantedContentFromProperty.bind(this, "city"),
"change:state": this.removeUnwantedContentFromProperty.bind(this, "state")
})
},
removeUnwantedContentFromString: function(a) {
return a ? a.replace(/[\s,.]+$/, "") : void 0
},
removeUnwantedContentFromProperty: function(a) {
var b = this.get(a),
c = this.removeUnwantedContentFromString(b);
if (b) return c !== b ? void this.set(a, c) : void this.updateLongAddress()
},
updateLongAddress: function() {
this.set("longaddress", this.getComputedLongAddress().substring(0, 255))
},
getComputedLongAddress: function() {
return this.get("address1") || this.get("address2") || this.get("city") || this.get("state") || this.get("postalcode") || this.get("country") ? c.reduce([this.get("address1"), this.get("address2"), this.get("city"), this.get("state"), this.get("postcode"), this.get("country")], function(a, b) {
return b = b.trim(), b && (a = a ? a + ", " + b : b), a
}, "") : ""
}
내가 필요 위의 코드를 아래에서 시도한 Jquery로 변환하지만 올바른 구문을 사용하여 모든 백본 함수를 Jquery로 변환하는 데 어려움을 겪고 있습니다.
$(function() {
initialize();
});
var initialize = function() {
$("#address1, #address2, #postcode, #country").on('change', updateLongAddress);
$("#city").on('change', removeUnwantedContentFromProperty);
$("#state").on('change', removeUnwantedContentFromProperty);
};
var removeUnwantedContentFromProperty = function(a) {
var b = this.get(a),
c = this.removeUnwantedContentFromString(b);
if (b) return c !== b ? void this.set(a, c) : void this.updateLongAddress()
};
var removeUnwantedContentFromString = function(a) {
return a ? a.replace(/[\s,.]+$/, "") : void 0
};
var updateLongAddress = function() {
this.set("longaddress", this.getComputedLongAddress().substring(0, 255))
};
var getComputedLongAddress = function() {
return this.get("#address1") || this.get("#address2") || this.get("#city") || this.get("#state") || this.get("postcode") || this.get("country") ? c.reduce([this.get("address1"), this.get("address2"), this.get("city"), this.get("state"), this.get("postcode"), this.get("country")], function(a, b) {
return b = b.trim(), b && (a = a ? a + ", " + b : b), a
}, "") : ""
};
어떤 도움을 주시면 감사하겠습니다.
애플리케이션에서 백본을 제거 하시겠습니까? 아니면 모델을 계속 사용 중입니까? – 76484
축소 된 코드를 리버스 엔지니어링 하시겠습니까? – 76484
@ 76484 백본을 제거하고 있으며 순수한 Jquery 코드를 사용해야하므로 리버스 엔지니어링이라고 말할 수 있습니다. – adam78