在 ATK4 中,如何使用选择框中选择的值重新加载页面

发布于 2024-12-05 06:02:28 字数 2133 浏览 0 评论 0原文

我有一个下拉列表定义如下的页面,

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

临风闻羌笛 2024-12-12 06:02:28

好的,所以我自己解决了。

我需要在 /templates/js 中创建一个名为 my_univ.js 的单独 .js 文件,其中包含以下内容

$.each({
viewMember: function(url, name){              
          document.location.href=url+'?member='+$(name).val();
}
},$.univ._import);

,并且在我想要下拉列表的页面中,我添加了一行来加载新的 .js
$this->js()->_load('my_univ');

如果没有给定添加行以从数据库表中填充下拉列表,则从 URL 或登录用户获取值

    if ($_GET['member']){
      $member=$_GET['member'];
    } else {
      $member=$p->api->auth->get('id');
    }

(包括将当前列表值设置为登录用户或 GET 参数

$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)->set($member);

    $l1->js('change')->univ()->viewMember($p->api->getDestinationURL(null),$l1);

,最后在主模型中用于填充页面,添加一个条件

    $st = $p->add('Model_Story');
    $st->addCondition('team_id', $p->api->auth->get('team_id'));
    $st->addCondition('responsible', $member);

最后一行告诉它当列表更改时,调用我上面的函数,将列表的名称传递给它,这样当用户更改下拉列表时,它会创建一个新的 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

$.each({
viewMember: function(url, name){              
          document.location.href=url+'?member='+$(name).val();
}
},$.univ._import);

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

    if ($_GET['member']){
      $member=$_GET['member'];
    } else {
      $member=$p->api->auth->get('id');
    }

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

$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)->set($member);

    $l1->js('change')->univ()->viewMember($p->api->getDestinationURL(null),$l1);

and finally, in the main model which is used to populate the page, add a condition

    $st = $p->add('Model_Story');
    $st->addCondition('team_id', $p->api->auth->get('team_id'));
    $st->addCondition('responsible', $member);

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.

尝蛊 2024-12-12 06:02:28

Agile Toolkit URL 处理中有一个机制,允许将其作为数组传递,格式如下:

{
    0:url,
    arg: val,
    arg2: val
}

atk4_loader 支持指定为数组的 URL,如下所示:

$(element).atk4_load({0:url, member:val});

现在,在 PHP 内部,您可以使用它来加载或重新加载参数。 http://demo.atk4.com/demo.html?t=5 。在您的情况下:

$area2=$this->add('HtmlElement')->set('Data is '.(int)$_GET['member'])`
$l1->js('change', $area2->reload('member'=>$l1->js()->val()));

或者您也可以调用:

$myview->js(true)->atk4_load(array($url,'member'=>$otherview->js()->val()));

这是通过 start-atk4.js 文件中定义的 $.atk4.addArgument 函数实现的。还有一个包装器 univ().addArgument()。您也许也可以使用它进行重定向,请尝试

$this->js()->univ()->redirect(
    array(
        $this->getDestinationURL('my page'),
        'member'=>$memberobj->js()->val()
    )
);

There is a mechanic in Agile Toolkit URL handling which allows to pass it as array in format like this:

{
    0:url,
    arg: val,
    arg2: val
}

atk4_loader supports URL specified as array, like this:

$(element).atk4_load({0:url, member:val});

Now, inside PHP, you can use that to load or reload with argument. http://demo.atk4.com/demo.html?t=5. In your case:

$area2=$this->add('HtmlElement')->set('Data is '.(int)$_GET['member'])`
$l1->js('change', $area2->reload('member'=>$l1->js()->val()));

or you can also call:

$myview->js(true)->atk4_load(array($url,'member'=>$otherview->js()->val()));

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

$this->js()->univ()->redirect(
    array(
        $this->getDestinationURL('my page'),
        'member'=>$memberobj->js()->val()
    )
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文