我对该uiSref指令有一个有趣的问题,我无法在网络上的任何地方找到解决方案(无论如何都是优雅的解决方案).基本上,我要求客户端能够单击资源表中的行并转到该资源的编辑视图.通常情况下,该uiSref指令运行得很漂亮,但问题在于我<td>在表的最后一个中有一个Bootstrap下拉列表,其中有一堆快速操作.HTML看起来像这样:
<table class="table table-bordedered table-hover">
<thead>
<tr>
<td>Name</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="resource in resources" ui-sref="edit({id: resource.id})">
<td ng-bind="resource.name"></td>
<td class="actions-column">
<div class="btn btn-xs btn-default" data-toggle="dropdown">
<i class="fa fa-cog"></i>
</div>
<ul class="dropdown-menu pull-right">
<li>
<a href="javascript:void(0)" ng-click="doSomethingCrazy(resource)">SOMETHING CRAZY</a>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
问题是,当我单击actions列中的按钮时,将uiSref覆盖下拉列表的默认操作并将我带到编辑页面.现在你可能会问自己"这很容易,为什么你不能阻止事件的传播!?"......不起作用.当我将其添加到actions列时:
<td class="actions-column" ng-click="$event.stopPropagation()">
Run Code Online (Sandbox Code Playgroud)
它会杀死下拉菜单的功能,但不显示任何内容.现在我有一个解决方法,我ngClick在<tr>元素上定义一个元素,然后根据点击的元素解密状态应该去的地方,如下所示:
<tr ng-repeat="resource in resources" ng-click="goToEdit(resource, $event)">
Run Code Online (Sandbox Code Playgroud)
JS看起来像这样:
scope.goToEdit = function(resource, event) {
// if the event.target has parent …Run Code Online (Sandbox Code Playgroud) 我对编程和灵丹妙药极其陌生.因此,我尽可能多地学习.但我遇到了麻烦.我正在寻找如何在另一个模块中使用我的函数的方法.我正在构建web-server,它将键值映射存储在内存中.为了保持地图临时,我决定使用Agent.这是我的代码的一部分:
defmodule Storage do
use Agent
def start_link do
Agent.start_link(fn -> %{} end, name: :tmp_storage)
end
def set(key, value) do
Agent.update(:tmp_storage, fn map -> Map.put_new(map, key, value) end)
end
def get(key) do
Agent.get(:tmp_storage, fn map -> Map.get(map, key) end)
end
end
Run Code Online (Sandbox Code Playgroud)
所以我试图将这些功能放到Web服务器的路由上:
defmodule Storage_router do
use Plug.Router
use Plug.Debugger
require Logger
plug(Plug.Logger, log: :debug)
plug(:match)
plug(:dispatch)
post "/storage/set" do
with {:ok, _} <- Storage.set(key, value) do
send_resp(conn, 200, "getting the value")
else
_ ->
send_resp(conn, 404, "nothing")
end
end
end …Run Code Online (Sandbox Code Playgroud)