简体   繁体   中英

How to insert value from jquery into knockout data-bind line?

The problem occurred while trying to insert new parameter into url property, which is inside select2.

<span><input type="hidden" class="expanded" 
                                     data-bind=" 
                                     select2ex: 
                                     {url: '(CONTROLLER_NAME)/(METHOD_NAME)?type=some_type&DocDate=PROBLEM!', 
                                     value: ID, 
                                     text: NAME, 
                                     options:{
                                        minimumInputLength: 1, 
                                        ajax: {
                                            params: {
                                                headerErrorsContainer: '#editor .errors-placeholder' 
                                            }, 
                                            cache: true}
                                     }, 
                                     select2InterfacePropName: 'SomeSelect2'}
                                     " 
                                     style="width: 100%"></input></span>

So how to get value from jquery into (PROBLEM!) place?

Maybe it's possible to some string interpolation?

...&DocDate={jquery call?}

You could try using a computed by assigning it to url parameter:

...
url: myComputed,
...

self.myComputed = ko.pureComputed(() => {
    var type = 'sometype';
    var docDate = 'mydate';
    return `(CONTROLLER_NAME)/(METHOD_NAME)?type=${type}&DocDate=${docDate}`;  //string interpolation
}, self);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM