我有一个基于Knockout JS的问题,带有一些级联选项列表,并切换出与它们相关的底层"活动"对象.
我创建了一个jsfiddle来演示这个问题.
我有一个用户界面,其中用户正在编辑主"标题"记录并添加/删除/编辑子记录.有一个用于编辑儿童记录的中心区域.想法是单击表中的子记录,这将成为正在中间区域编辑的记录.
我遇到的问题是由于第二个下拉列表中的事物列表根据第一个下拉列表而变化.在活动记录更改之前,这很好.如果类别因活动记录更改而更改,则"事物"列表也会更改.此时,清除新活动子记录中选择的"事物"(第二个下拉列表).
我假设新活动记录的值发生了变化,但是因为它没有出现在旧列表中(如果类别已更改),则会被清除.然后更改项目本身列表(包括适当的值),但此时该值已从视图模型中消失.
(我意识到这是一个冗长的解释,希望jsfiddle明确表示)
如何更改下拉列表中的项目列表以及视图模型中的选定值,同时不会丢失所选值?
HTML:
<label>Some header field</label>
<input type="text" id="txtSomeHeaderField" data-bind="value: HeaderField" />
<fieldset>
<legend>Active Child Record</legend>
<label>Category</label>
<select id="ddlCategory" data-bind="options: categories, value: ActiveChildRecord().Category, optionsCaption:'Select category...'" ></select>
<label>Things</label>
<select id="ddlThings" data-bind="options: ThingsList, value: ActiveChildRecord().Favorite, optionsCaption:'Select favorite thing...'" ></select>
</fieldset>
<button data-bind="click: AddChildRecord" >Add a child record</button>
<table id="tblChildRecords" border>
<thead>
<tr>
<th>Category</th>
<th>Favorite Thing</th>
</tr>
</thead>
<tbody data-bind="foreach: ChildRecords">
<tr data-bind="click: ChildRecordClicked, css: {activeRow: ActiveChildRecord() === $data}" >
<td data-bind="text: Category"></td> …Run Code Online (Sandbox Code Playgroud) javascript data-binding cascadingdropdown viewmodel knockout.js
我有一个 Powershell 脚本,我需要知道 Docker Desktop 当前是否正在运行。
我读到,一种方法是使用docker ps并查看是否返回容器列表或错误消息。但我很难在实际脚本中使用它。我还没有弄清楚如何正确捕获结果并对其采取行动。
这是我到目前为止所拥有的:
function IsDockerDesktopRunning()
{
$dockerPsResult = docker ps | Out-String
Write-Host "Result is:"
Write-Host $dockerPsResult
if (($dockerPsResult).StartsWith("error"))
{
return $false
}
return $true
}
$isRunning = IsDockerDesktopRunning
Write-Host $isRunning
Run Code Online (Sandbox Code Playgroud)
当它不运行时,结果如下所示:
error during connect: This error may indicate that the docker daemon is not running.: Get "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/json": open //./pipe/docker_engine: The system cannot find the file specified.
Result is:
True
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,命令的输出看起来docker ps是在执行时获取的输出,并且变量未填充。
有没有办法正确捕获输出? 或者,我应该以不同的方式解决这个问题吗?