Coder Social home page Coder Social logo

建议确定后增加回调 about larea HOT 2 OPEN

xfhxbb avatar xfhxbb commented on July 19, 2024
建议确定后增加回调

from larea.

Comments (2)

woleicom avatar woleicom commented on July 19, 2024 2

area2.init({ 'trigger': '#demo2', 'valueTo': '#value2', 'keys': { id: 'value', name: 'text' }, 'type': 2, 'data': [provs_data, citys_data, dists_data], 'ok':function (value) { console.log(value) }, 'close':function () { console.log(0) } });

源码:
341行:
if(this.valueTo){ this.valueTo.value= provinceCode +((cityCode)?(',' + cityCode):('')) + ((countyCode)?(',' + countyCode):('')); } _self.params.ok&&_self.params.ok([provinceText,cityText,countyText]); _self.close(e); }, close: function(e) { e.preventDefault(); var _self = this; var evt = new CustomEvent('input'); _self.trigger.dispatchEvent(evt); document.body.removeChild(_self.gearArea); _self.gearArea=null; _self.params.close&&_self.params.close(); }

ok返回选择地址的数组

from larea.

Jogiter avatar Jogiter commented on July 19, 2024

+1 同建议增加回调,可以自主控制结果

var addrText = provinceText + ((cityText)?(',' + cityText):(''))+ ((countyText)?(',' + countyText):(''));
var addrCode = provinceCode +((cityCode)?(',' + cityCode):('')) + ((countyCode)?(',' + countyCode):(''));
if (this.params.finish && typeof this.params.finish === 'function') {
    this.params.finish(addrText, addrCode, [provinceVal, cityVal, countyVal]);
} else {
    addrText = addrText.replace(/县,|市辖区,/ig, '').replace(/,/ig, ''); // 直辖市结果处理
    _self.trigger.value = addrText;
    _self.value = [provinceVal, cityVal, countyVal];
    if(this.valueTo){
        this.valueTo.value= addrCode;
    }
}

这样,在init的时候

var area = new LArea();
area.init({
    'trigger': '#trigger', 
    'keys': {
        id: 'id',
        name: 'name'
    },
    'type': 1, 
    'data': LAreaData, 
    finish: function(text, code, value) {
        // 自己选择显示结果
    }
});

from larea.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.