在 ATK4 中,如何使用选择框中选择的值重新加载页面
我有一个下拉列表定义如下的页面,
$memb=$this->api->db->dsql()->table('vscrum_member m')
->field('m.id')
->field('m.name')
->where('m.team_id',$p->api->auth->get('team_id'))
->order('m.xlastname, m.xfirstname')
->do_getAssoc();
$f=$p->add('Form');
$l1=$f->addField('dropdown','member')->setValueList($memb);
当用户更改下拉列表时(GET 或 POST 都可以),我需要重新加载页面并传递下拉列表的当前值。
在 ATK4 中,我可以用它来重定向页面
$l1->js('change')->univ()->redirect($this->api->getDestinationURL(null));
,理论上,您可以添加一个值数组作为第二个参数,该参数将成为 GET 变量,
$l1->js('change')->univ()
->redirect($this->api->getDestinationURL(null, array('member'=>123);
但由于我不知道在客户端选择的值,所以这没有帮助。 在javascript中,您可以通过使用来选择选择框的当前值
this.options[this.selectedIndex].value
,在jquery中您可以使用
$('#name').val();
,但到目前为止,我得到的最接近的是使用
$l1->js('change')->univ()->redirect($this->api->getDestinationURL(null,
array('member'=>$l1->js(true)->val())));
这会重定向到
http://localhost/test1/scrumwall?
member=%24%28%27%23test1_scrumwall_form_member%27%29.val%28%29
所以任何想法正确的语法是什么,以便它评估所选选项的 id,而不是将下拉列表的名称作为参数值?
$l1->js('change') 位在下拉列表中添加了一个 onchange="" - 也许有某种方法可以 直接在引号之间插入 javascript 但看不到任何示例。
我尝试了这种方式
$l1->js('change')->univ()->js(null,
"window.location='http://localhost/test1/scrumwall?member='+this.options[this.selectedIndex].value");
,但它没有将其放在 onchange 的引号之间,而是将其添加为绑定到下拉列表的 jquery 函数(请参阅下面的浏览器视图源代码中的结果),但这也不起作用。
$('#test1_scrumwall_form_member').bind('change',function(ev){
ev.preventDefault();ev.stopPropagation();
$('#test1_scrumwall_form_member').univ().js(null,'window.location=\x27
http://localhost/test1/scrumwall?member=\x27+this.options[this.selectedIndex].value')
});
所以我不知道如何用 ATK4 做到这一点。任何帮助表示赞赏。
谢谢
I have a page with a dropdown list defined as follows
$memb=$this->api->db->dsql()->table('vscrum_member m')
->field('m.id')
->field('m.name')
->where('m.team_id',$p->api->auth->get('team_id'))
->order('m.xlastname, m.xfirstname')
->do_getAssoc();
$f=$p->add('Form');
$l1=$f->addField('dropdown','member')->setValueList($memb);
I need the page to be reloaded passing the current value of the dropdown when it is changed by the user (either GET or POST is fine).
In ATK4, i can cause a redirect of the page with this
$l1->js('change')->univ()->redirect($this->api->getDestinationURL(null));
and in theory, you can add an array of values as the second parameter which become GET variables
$l1->js('change')->univ()
->redirect($this->api->getDestinationURL(null, array('member'=>123);
but as i dont know the value chosen on the client side, this doesnt help.
In javascript, you can select the current value of a select box by using
this.options[this.selectedIndex].value
and in jquery you can use
$('#name').val();
but so far, the closest i've got is using
$l1->js('change')->univ()->redirect($this->api->getDestinationURL(null,
array('member'=>$l1->js(true)->val())));
This does the redirect to
http://localhost/test1/scrumwall?
member=%24%28%27%23test1_scrumwall_form_member%27%29.val%28%29
So any ideas what the correct syntax would be so that it evaluates the id of the option chosen, rather than putting the name of the dropdown list as the parameter value ?
The $l1->js('change') bit adds an onchange="" to the dropdown list - maybe there is some way to
insert javascript directly between the quotes but couldnt see any examples.
I tried it this way
$l1->js('change')->univ()->js(null,
"window.location='http://localhost/test1/scrumwall?member='+this.options[this.selectedIndex].value");
but it doesnt put this between the quotes on the onchange, instead it adds it as a jquery function (see result in browser view source below) bound to the dropdown but this also doesnt work.
$('#test1_scrumwall_form_member').bind('change',function(ev){
ev.preventDefault();ev.stopPropagation();
$('#test1_scrumwall_form_member').univ().js(null,'window.location=\x27
http://localhost/test1/scrumwall?member=\x27+this.options[this.selectedIndex].value')
});
so i cant figure out how to do this with ATK4. Any assistance appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,所以我自己解决了。
我需要在 /templates/js 中创建一个名为 my_univ.js 的单独 .js 文件,其中包含以下内容
,并且在我想要下拉列表的页面中,我添加了一行来加载新的 .js
$this->js()->_load('my_univ');
如果没有给定添加行以从数据库表中填充下拉列表,则从 URL 或登录用户获取值
(包括将当前列表值设置为登录用户或 GET 参数
,最后在主模型中用于填充页面,添加一个条件
最后一行告诉它当列表更改时,调用我上面的函数,将列表的名称传递给它,这样当用户更改下拉列表时,它会创建一个新的 URL,其值为选定的列表并使用重新加载页面URL http://localhost/test1/scrumwall?member=N 其中 N 是所选的成员在列表中 - 太棒了。
OK, so i worked it out myself.
I needed to create a separate .js file in /templates/js called my_univ.js with the following contents
and in the page where i want the dropdown list, i added a line to load the new .js
$this->js()->_load('my_univ');
get the values from the URL or the logged in user if none given
add lines to get populate the dropdown from a database table (including setting the current list value to either the logged in user or the GET parameter
and finally, in the main model which is used to populate the page, add a condition
The last line tells it when the list changes, to call my above function passing it the name of the list so when the user changes the dropdown list, it creates a new URL with the vaue of the selected list and reloads the page using the URL http://localhost/test1/scrumwall?member=N where N is the member chosen in the list - fantastic.
Agile Toolkit URL 处理中有一个机制,允许将其作为数组传递,格式如下:
atk4_loader 支持指定为数组的 URL,如下所示:
现在,在 PHP 内部,您可以使用它来加载或重新加载参数。 http://demo.atk4.com/demo.html?t=5 。在您的情况下:
或者您也可以调用:
这是通过 start-atk4.js 文件中定义的 $.atk4.addArgument 函数实现的。还有一个包装器 univ().addArgument()。您也许也可以使用它进行重定向,请尝试
There is a mechanic in Agile Toolkit URL handling which allows to pass it as array in format like this:
atk4_loader supports URL specified as array, like this:
Now, inside PHP, you can use that to load or reload with argument. http://demo.atk4.com/demo.html?t=5. In your case:
or you can also call:
This is implemented through $.atk4.addArgument function defined in start-atk4.js file. There is also a wrapper univ().addArgument(). You might be able to use it for redirect also, try