我很难在link_to UrlHelper中添加查询字符串参数.我有一个索引视图,例如,它具有用于排序,过滤和分页的UI元素(通过will_paginate).will_paginate插件正确管理查询字符串参数的页内持久性.
是否有自动机制将查询字符串参数添加到给定命名路由,或者我是否需要手动执行此操作?对这个看似简单的结构的大量研究让我一无所知.
编辑
一些挑战:
如果我有两个查询字符串参数,存储桶和排序,如何在link_to中为其中一个设置特定值,同时保留另一个的当前值?例如:
<%= link_to "0", profiles_path(:bucket => '0', :sorting=>?? ) %>
Run Code Online (Sandbox Code Playgroud)如果我有多个查询字符串参数,bucket&sorting&page_size,并且我想将值设置为其中之一,是否有办法'自动'包含其余参数的名称和值?例如:
<%= link_to "0", profiles_path(:bucket => '0', [include sorting and page_size name/values here] ) %>
Run Code Online (Sandbox Code Playgroud)will_paginate插件自动管理其页面变量和其他查询字符串变量.似乎没有用于管理页面大小的自动UI元素.虽然我已经看到了创建页面大小选择列表的代码,但我宁愿为此设置A元素(如SO).这个挑战的一部分与#2有关,部分与基于记录的存在/不存在隐藏/显示该UI元素有关.换句话说,如果有页面记录,我只想包含页面大小的链接.此外,我更喜欢自动包含其他QS变量(即页面,存储桶,排序),而不必在link_to中按名称包含它们.
假设我在.h文件中声明了一个typedef:
typedef enum {
JSON,
XML,
Atom,
RSS
} FormatType;
Run Code Online (Sandbox Code Playgroud)
我想构建一个将typedef的数值转换为字符串的函数.例如,如果邮件[self toString:JSON]已发送; 它会返回'JSON'.
该函数看起来像这样:
-(NSString *) toString:(FormatType)formatType {
//need help here
return [];
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句,如果我尝试这种语法
[self toString:FormatType.JSON];
Run Code Online (Sandbox Code Playgroud)
要将typedef值传递给方法,我收到一个错误.我错过了什么?
我有一个在开发环境中缓存页面的RoR应用程序(ruby v1.8.7; rails v2.3.5).这不是一个问题,但缓存页面的a元素是不正确的.
我没有对development.rb文件进行任何更改,我没有故意向控制器添加任何缓存命令.
我已经尝试清除浏览器(OSX上的Firefox 3.5)cookie和页面缓存(localhost).我也重启了Mongrel.似乎没有任何帮助.
我错过了什么?
我正在尝试在包中创建一个返回表的函数.我希望在包中调用一次函数,但能够多次重复使用它的数据.虽然我知道我在Oracle中创建临时表,但我希望保持干燥.
到目前为止,这就是我所拥有的:
标题:
CREATE OR REPLACE PACKAGE TEST AS
TYPE MEASURE_RECORD IS RECORD (
L4_ID VARCHAR2(50),
L6_ID VARCHAR2(50),
L8_ID VARCHAR2(50),
YEAR NUMBER,
PERIOD NUMBER,
VALUE NUMBER
);
TYPE MEASURE_TABLE IS TABLE OF MEASURE_RECORD;
FUNCTION GET_UPS(
TIMESPAN_IN IN VARCHAR2 DEFAULT 'MONTLHY',
STARTING_DATE_IN DATE,
ENDING_DATE_IN DATE
) RETURN MEASURE_TABLE;
END TEST;
Run Code Online (Sandbox Code Playgroud)
身体:
CREATE OR REPLACE PACKAGE BODY TEST AS
FUNCTION GET_UPS (
TIMESPAN_IN IN VARCHAR2 DEFAULT 'MONTLHY',
STARTING_DATE_IN DATE,
ENDING_DATE_IN DATE
) RETURN MEASURE_TABLE IS
T MEASURE_TABLE;
BEGIN
SELECT ...
INTO T …Run Code Online (Sandbox Code Playgroud) 我试图存储对我的应用程序属性所做的更改.该.properties文件位于resources包中,该包与包含我的UI和模型的包不同.
我用以下方式打开了包裹:
this.getClass().getClassLoader().getResourceAsStream("resources/settings.properties")
Run Code Online (Sandbox Code Playgroud)
是否有一个功能等同于允许我在同一.Properties文件中持久更改属性类?
我需要确定一个PSCustomObjects 数组是否包含一个Title属性与值匹配的项.我需要一个布尔值来与Pester断言一起使用:
$Items -<function> $Name | Should Be $True
Run Code Online (Sandbox Code Playgroud)
假设:
$Items = @()
$Items += [PsCustomObject]@{Title='foo';Url='http://f.io'}
$Items += [PsCustomObject]@{Title='bar';Url='http://b.io'}
Run Code Online (Sandbox Code Playgroud)
Contains 不起作用:
PS> $Items -contains 'foo'
False
Run Code Online (Sandbox Code Playgroud)
Match 返回匹配的实例,但它不是布尔值:
PS> $Items -match 'foo'
Title Url
----- ---
foo http://f.io
Run Code Online (Sandbox Code Playgroud)
我想我可以:
($Items -Match $Name).Count | Should Be 1
Run Code Online (Sandbox Code Playgroud)
有更好的选择吗?
我正在尝试修改标准的Swing JTree以使用和不使用复选框来混合节点.这是一个例子:

当我尝试选中/取消选中其中一个复选框(本例中为"User 01"节点)时,树会丢失节点:

我的代码是这个例子的改编:http://forums.sun.com/thread.jspa?threadID = 5321084&start = 13.
而不是像这样在DefaultMutableTreeNode中嵌入JCheckBox:
new DefaultMutableTreeNode(new CheckBoxNode("Accessibility", true));
Run Code Online (Sandbox Code Playgroud)
我认为创建一个派生自DefaultMutableTreeNode的模型节点更有意义,我称之为JTreeNode.该类自动将DefaultMutableTreeNode的UserObject设置为JCheckBox.TreeCellRenderer使用类的ShowCheckBox属性来确定是否使用了JCheckBox或DefaultTreeCellRenderer.JTreeNode的用法如下:
JTreeNode user01 = new JTreeNode("User 01");
user01.setShowCheckBox(true);
user01.setSelected(true);
Run Code Online (Sandbox Code Playgroud)
我认为问题在于实现TreeCellEditor的类,特别是在getCellEditorValue()或getTreeCellEditorComponent()方法中.我怀疑这个问题与getCellEditorValue()有关,返回DefaultMutableTreeNode的派生,而不是更简单的模型实例.
public Object getCellEditorValue() {
JCheckBox checkBox = renderer.getCheckBoxRenderer();
JTreeNode node = new JTreeNode(checkBox.getText());
node.setShowCheckBox(true);
node.setSelected(checkBox.isSelected());
return node;
}
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
Component editor = renderer.getTreeCellRendererComponent(tree, value, true, expanded, leaf, row, true);
// editor always selected / focused
ItemListener itemListener = …Run Code Online (Sandbox Code Playgroud) 我有两节课:
class User < ActiveRecord::Base
:has_one :foo
end
class Foo < ActiveRecord::Base
:belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
Foo是可选的.
我创建了以下路由:
resources :users do
resources :foo
end
Run Code Online (Sandbox Code Playgroud)
这导致以下路线:
GET /users/:user_id/foo(.:format) {:controller=>"foos", :action=>"index"}
user_foos POST /users/:user_id/foo(.:format) {:controller=>"foos", :action=>"create"}
new_user_foo GET /users/:user_id/foo/new(.:format) {:controller=>"foos", :action=>"new"}
GET /users/:user_id/foo/:id(.:format) {:controller=>"foos", :action=>"show"}
PUT /users/:user_id/foo/:id(.:format) {:controller=>"foos", :action=>"update"}
user_foo DELETE /users/:user_id/foo/:id(.:format) {:controller=>"foos", :action=>"destroy"}
edit_user_foo GET /users/:user_id/foo/:id/edit(.:format) {:controller=>"foos", :action=>"edit"}
Run Code Online (Sandbox Code Playgroud)
问题:
谢谢你的时间.
从文件中加载PowerShell哈希表的问题?记录如何将包含PSON格式的哈希表的文件加载到变量中,但是如何将哈希表保存为PSON格式的文件?
哈希表:
@{
"name" = "report 0"
"parameters" = @(
@{"name" = "parameter 0"; "default" = 1; "values"=1,2,3,4},
@{"name" = "parameter 1"; "default" = 'A'; "values" = 'A','B','C'}
)
}
Run Code Online (Sandbox Code Playgroud) 我希望Write-Verbose在脚本和函数中使用命令行开关.它在脚本(.ps1)文件中按预期工作,但在模块(.psm1)文件中不起作用 - 在模块中忽略命令行开关.
运行以下脚本:
PS> .\scaffold.ps1 -verbose
Run Code Online (Sandbox Code Playgroud)
生产:
VERBOSE: starting foo
path: c:\bar.txt
[missing entry here - 'verbose path: c:\bar.txt']
VERBOSE: ending foo
Run Code Online (Sandbox Code Playgroud)
scaffold.ps1:
[cmdletbinding()]
param()
import-module Common -force
write-verbose "starting foo"
foo "c:\bar.txt"
write-verbose "ending foo"
Run Code Online (Sandbox Code Playgroud)
Common.psm1:
function foo {
[cmdletbinding()]
Param(
[string]$path
)
write-host "path: $path"
write-verbose "verbose path: $path"
}
Run Code Online (Sandbox Code Playgroud)
此时我没有将清单(.psd1)与模块(.psm1)相关联.
是否需要使用特定于模块的语法?
**编辑**
我需要的是一种确定-verbose标志是否已在.PS1文件上设置的方法,以便我可以将其传递给.PSM1文件.
scaffold.ps1:
[cmdletbinding()]
param()
import-module Common -force
write-verbose "starting foo"
foo "c:\bar.txt" $verbose_flag # pass verbose setting to module based …Run Code Online (Sandbox Code Playgroud) powershell ×3
java ×2
swing ×2
c ×1
caching ×1
enums ×1
expression ×1
file-io ×1
has-one ×1
jcheckbox ×1
jtree ×1
objective-c ×1
oracle10g ×1
package ×1
persistence ×1
pester ×1
plsql ×1
properties ×1
query-string ×1
rendering ×1
routing ×1
typedef ×1