作为一个最小的例子,我想将一个文本文件导入打字稿并将其打印到控制台而不使用fs. 像这样的东西:
import text from './foo.txt'
console.log(text)
Run Code Online (Sandbox Code Playgroud)
我找到了很多解决方案的例子,比如这个,我已经创建了一个typings.d.ts包含内容的文件
declare module '*.txt' {
const content: string;
export default content;
}
Run Code Online (Sandbox Code Playgroud)
但是当我构建项目时,我仍然看到“错误 TS2307:找不到模块 './foo.txt'。”
我错过了什么?
这里的示例存储库:https : //github.com/gferreri/typescript-import-test
Alamofire的文档说它产生cURL调试输出.但是对于我的生活,我无法弄清楚如何根据我的要求检索cURL.有人可以启发我在调试控制台中显示cURL请求的正确语法吗?
假设我有一个简单的表单请求
Alamofire.request(.POST, servicePath, parameters: requestParams, encoding: .JSON)
Run Code Online (Sandbox Code Playgroud)
我在哪里可以注入一个print()来查看生成的请求?
我有一个简单的窗口,带有一个带有命令的ViewModel按钮.
我希望如果MyCommand.CanExecute()为false,则禁用该按钮.但似乎WPF只会在首次绘制窗口时设置IsEnabled属性.任何后续操作都不会影响按钮的可见状态.我正在使用Prism的DelegateCommand.
我的看法:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Click Here" Command="{Binding MyCommand}" Width="100" Height="50"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
和我的ViewModel:
public class MyVM : NotificationObject
{
public MyVM()
{
_myCommand = new DelegateCommand(DoStuff, CanDoStuff);
}
private void DoStuff()
{
Console.WriteLine("Command Executed");
_myCommand.RaiseCanExecuteChanged();
}
private bool CanDoStuff()
{
var result = DateTime.Now.Second % 2 == 0;
Console.WriteLine("CanExecute is {0}", result);
return result;
}
private DelegateCommand _myCommand;
public ICommand MyCommand
{
get
{
return _myCommand;
}
}
}
Run Code Online (Sandbox Code Playgroud)
50%的时间,当我的应用程序加载时,按钮被正确禁用.但是,如果在窗口加载时启用它,并且我单击按钮执行命令,我希望该按钮有50%的时间被禁用,但它永远不会.该命令不会执行,但我仍然可以单击该按钮.当CanExecute()为false时,如何让WPF理解应该禁用该按钮?
我正在开发一个必须使用Windows经典主题运行的WPF应用程序.该应用程序创建一个包含ListBox的对话框.显示对话框时,在接受任何输入之前必须禁用1秒.我用一个样式触发器来完成它,它的工作原理.但是,ListBox在禁用时显示白色背景,我似乎无法摆脱它.使用aero主题时,以下样式资源可修复此问题:
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
Run Code Online (Sandbox Code Playgroud)
但是在使用Windows经典主题时,会再次出现白色背景.我怎样才能解决经典主题的情况???
我想使用不渲染任何x轴或网格线的ios图表渲染(堆叠)水平条形图.我已经禁用了我能找到的每个设置,但是底部的x轴仍然呈现.
func setUpBarChart() {
// General bar chart settings
barChart.pinchZoomEnabled = false
barChart.drawGridBackgroundEnabled = false
barChart.drawBarShadowEnabled = false
barChart.drawValueAboveBarEnabled = false
barChart.drawBordersEnabled = false
barChart.drawMarkers = false
barChart.legend.enabled = false
barChart.descriptionText = ""
barChart.drawBordersEnabled = false
// Left-axis settings
barChart.leftAxis.drawLabelsEnabled = false
barChart.leftAxis.drawTopYLabelEntryEnabled = false
barChart.leftAxis.drawAxisLineEnabled = false
// x-axis settings
barChart.xAxis.drawAxisLineEnabled = false
barChart.xAxis.drawGridLinesEnabled = false
barChart.xAxis.drawLabelsEnabled = false
barChart.xAxis.enabled = false
// add some dummy data
let entry = BarChartDataEntry(values: [10,2,5], xIndex: 0)
let set = BarChartDataSet(yVals: [entry], …Run Code Online (Sandbox Code Playgroud) 我想为我的 iOS 应用程序编写一个测试,以验证从自定义注册的 URL 方案启动应用程序时显示正确的屏幕内容。
例如,用户收到一封电子邮件,其中包含 的链接myapp://action1/1234。当他们点击此链接时,我的应用程序将启动并且屏幕显示“1234”。
在didFinishLaunchingWithOptions我的 AppDelegate 中检查是否launchOptions?[UIApplicationLaunchOptionsURLKey]存在并采取适当的操作。
如何编写 UI 测试,以便应用程序启动时应用程序 launchOptions 字典包含预期的 URL?
我想构建一种方法,在会话因不活动而到期时自动将用户重定向到Timeout.aspx.我的应用程序使用表单身份验证,并且在相同的aspx页面中严重依赖于用户交互的更新面板,因此我不想在页面级计时器到期后简单地重定向.出于同样的原因,我不能使用'<meta http-equiv ="refresh"/>'
我想要做的是使用一个名为IsSessionTimedOut()的方法创建一个简单的ajax Web服务,它只返回一个布尔值.我将使用javascript计时器定期调用该方法,如果它返回true,则重定向到Timeout.aspx.但是,我不希望调用此方法来重置会话超时计时器,或者由于服务调用会话永远不会超时.是否有一种干净的方法来避免这种捕获-22?希望有一个简单的解决方案,迄今为止我没有找到.
在我的 UI 测试中,我想在运行我的 UI 测试之前调用远程端点来重置数据库状态。这很好用,但我想确保在请求失败时我能捕捉到任何错误。我想做的是:
下面是一些示例代码,说明了我的观点:
override func setUp() {
super.setUp()
var finished = false
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)) {
let request = Alamofire.request(.GET, "http://xxx.xxx.xxx.xxx/resetdb")
request.response() {
request, response, data, error in
if let _ = error {
let message = "Could not call remote helper -- \(response?.statusCode)"
XCTFail(message) // doesn't work
debugPrint(message) // can't see this anywhere
}
finished = true
}
}
while !finished {
NSRunLoop.currentRunLoop().runMode(NSDefaultRunLoopMode, beforeDate: NSDate.distantFuture())
}
app = XCUIApplication()
app.launch()
}
Run Code Online (Sandbox Code Playgroud)