简体   繁体   English

在一页上的多个UI选择控件之间区分箭头单击

[英]Differentiating arrow clicks between multiple UI-Select controls on one page

Hi I would like to customize behavior of the ui-select little bit. 嗨,我想自定义ui选择的行为。 I use two bootstap themed ui-select controls on my page with the help of templatecaches. 我借助templatecaches在页面上使用了两个引导主题的ui-select控件。 In the template, I wired up arrow button click event using ng-click tag. 在模板中,我使用ng-click标记连接了箭头单击事件。 That way I can easily catch the click event on the arrow button, and in my controller I can open a popup using function, for instance: 这样,我可以轻松捕获箭头按钮上的click事件,并且可以在控制器中使用函数打开一个弹出窗口,例如:

<button ng-click = "someFunctionInTheScope()">

For instance if I have two of those ui-select elements in my view, I need to differentiate which arrow button is clicked to display the correct popup. 例如,如果我的视图中有两个ui-select元素,则需要区分单击哪个箭头按钮以显示正确的弹出窗口。 Since I am using the same template for two ui-select controls and since theoretically I can have any number of these controls on my page, I can not easily add a parameter to the method in the template to differentiate which arrow image of which ui-select control is clicked: 由于我将同一模板用于两个ui选择控件,并且从理论上讲,我可以在页面上使用任意数量的这些控件,因此我无法轻松地向模板中的方法添加参数来区分哪个ui-选择控件被单击:

<button ng-click= "someFunctionInTheScope(1)">

Because both ui-select control would be using the same template code and 1 would be passed to the controller function for both of them. 因为两个ui-select控件都将使用相同的模板代码,并且两个都将1传递给控制器​​功能。

Therefore I need to find a more clever way of changing the template dynamically once and for each control. 因此,我需要找到一种更聪明的方式来为每个控件一次动态地更改模板。

So I thought about having something like 所以我想到了类似的东西

<button ng-click= "someFunctionInTheScope($select.id)">

but when I debug it I see that functions parameter is undefined, every time it is clicked. 但是当我调试它时,每次单击该函数时,都会看到未定义functions参数。

Can somebody please show me how to hack this? 有人可以告诉我如何破解吗?

There is no id property on the $select object. $select对象上没有id属性。 You're best bet is to pass something through the scope of the element containing the ui-select boxes. 最好的办法是在包含ui-select框的元素范围内传递内容。 In other words, your code needs to generate a unique identifier for each ui-select box you have. 换句话说,您的代码需要为您拥有的每个ui选择框生成一个唯一的标识符。 This could be the $index property of an ng-repeat block, a timestamp, or something dependent on other context. 这可能是ng-repeat块的$index属性,时间戳或依赖于其他上下文的内容。

A little more context and I can provide a more specific answer. 多一点背景,我可以提供更具体的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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