私は以下のフォームフィールドを持っています。ユーザーがアドレスフィールドのいずれかを変更すると、すべてのフォームフィールドの連結された文字列であるlongaddressフィールドを更新したいと思います。 longaddressは、Googleマップのオートコンプリートに渡されるので、私は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