SOLVED!
I was so stupid! Sorry.
The decision is to add not just iterable values (ids=1,5,8) in request vars
but make multiple request vars (ids=1&ids=5&ids=8).
So the view code is:
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function(){
var selected_id = [];
$.each($("input[name='food']:checked"), function(){
selected_id.push($(this).val());
});
text = '?'
for (var i in selected_id) {
console.log(selected_id[i]);
text += 'ids=' + selected_id[i] + '&'
}
window.location.href="{{=URL('promo3')}}" + text;
});
});
</script>
In controller:
mmm = []
for i in request.vars.ids:
mmm.append(i)
rows = db(db.hes.id.belongs(mmm)).select()
On Thursday, September 10, 2015 at 2:35:26 PM UTC+3, Vladimir Makarov wrote:
>
> *Another words, is there a way to select all rows form table that belongs
> all id in request vars*
>
> *http:/________/_______/promo3?ids=1,2,3*
>
> *It's easy to select promo3?ids=1. But I failed to select **ids=3,8,15
> for example.*
> *Where am I wrong?*
>
>
>
> On Thursday, September 10, 2015 at 2:27:59 PM UTC+3, Vladimir Makarov
> wrote:
>>
>> Trying to use
>> window.location.href='{{=URL('promo3')}}' + '?' + $.param({ids: ids});
>>
>> but the code is generated invalid link with additional symbols:
>> http://______/_____/promo3?ids*%5B%5D*=3
>>
>> Some manipulations and the code is work perfectly:
>> window.location.href="{{=URL('promo3_order_det')}}?ids=" + selected_id;
>>
>> And how to select all rows from the db table that belongs selected list?
>> When I check only one checkbox and pass only one id to controller dev the
>> result is correct.
>> But multiple checked items generate error. I use this code to select:
>> rows = db(db.hes.id.belongs(request.vars.ids)).select()
>>
>>
>>
>> On Thursday, September 10, 2015 at 1:44:54 PM UTC+3, Leonel Câmara wrote:
>>>
>>> How about this:
>>>
>>> window.location.href='{{=URL('promo3')}}' + '?' + $.param({ids: ids});
>>>
>>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.