我正在努力,Backbone.js我想知道你是否可以像设置模型的默认值一样设置默认值?
我试图在UITableViewCell填充tableview时使用以下代码自定义a的字体.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
// Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString *temp = [[NSString alloc] initWithString:[[stories objectAtIndex: storyIndex] objectForKey: @"title"]];
cell.textLabel.text = temp;
[[cell textLabel] setTextColor:[UIColor colorWithRed:154.0/255.0 green:14.0/255.0 blue:2.0/255.0 alpha:1]];
[[cell textLabel] setFont:[UIFont systemFontOfSize:12.0]];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
对于我的生活,我不知道为什么它不会改变字体!如果我在单元格文本中进行硬编码,上面的代码也能正常工作cell.textLabel.text = @"TEST";
有什么建议?谢谢!
有没有办法从package.json文件传入数组到grunt.js?我尝试了几种不同的方式,但似乎没有一种方法可行.我目前有:
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: '<json:package.json>',
lint: {
files: '<%= pkg.lint.join(", ") %>'
}
// Default task 'lint qunit concat min'
grunt.registerTask('default', 'lint');
};
Run Code Online (Sandbox Code Playgroud)
的package.json
{
"lint": [
"grunt.js",
"test.js"
]
}
Run Code Online (Sandbox Code Playgroud)
我能找到的唯一解决方案是传入数组的特定索引; 例如<%= pkg.lint [0]%>.在此先感谢您的帮助!
我无法弄清楚为什么我的rails视图无法识别flash [:notice]或flash [:error].关于正在呈现的局部视图,我一直收到以下错误.具体错误是:
ActionView :: Template :: Error(当你没想到它时你有一个nil对象!你可能期望一个Array的实例.在评估nil时出错.[]):
在我的控制器中我有
def index
@organisms = Organism.all
flash[:error] = "test"
flash[:notice] = "test"
respond_to do |format|
format.html
format.json { render :json => @organisms }
end
end
Run Code Online (Sandbox Code Playgroud)
在我的index.html.erb文件中,我渲染了一个部分:
<%= render "shared/flash" %>
Run Code Online (Sandbox Code Playgroud)
部分具有以下代码.
<div id="flashes">
<% if flash[:notice] %>
<p id="flash_notice" class="messages notice"><%= flash[:notice] %></p>
<%= javascript_tag "$('#flash_notice').effect('highlight',{},1000);" %>
<% end %>
<% if flash[:error] || flash[:errors] %>
<p id="flash_errors" class="messages errors"><%= flash[:error] || flash[:errors] %></p>
<%= javascript_tag "$('#flash_errors').effect('highlight',{},1000);" %>
<% end %>
<% …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用Rails send_file方法在我的应用程序之外发送多个文件.它遍历所有文件,但只发送目录中的最后一个文件.这是我的代码.
Dir.foreach(@dir) do |entry|
if entry != "." && entry != ".." && entry != ".DS_Store" && entry != ".title"
send_file(@dir + entry, :disposition => 'inline')
logger.info("File: " + @dir + entry)
end
end
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏!
我遇到了一个相当奇怪的问题.我有一个可以通过CSS3旋转的div.div有一个前div子和后div子,后面div有-webkit-transform: rotateY( 180deg )set.
一旦父元素被旋转以显示div的背面的问题,它将仅检测div的一侧上的子元素的点击,特别是div或右侧的后半部分.正面div检测元素整个面上的咔嗒声.此外,z指数很好.我认为问题可能是由于旋转和浏览器显示一半"更近"?
这打破的代码非常复杂,所以我创建了一个测试文件来演示下面的问题.我正在使用我为3D转换编写的jQuery插件,可以在这里找到https://github.com/pwhisenhunt/jquery.transform/blob/master/jquery.transform.js.
编辑:经过实验,单击按钮元素只能记录100-200px而不是0-100px.换句话说,它实际上只是在div的后半部分注册.
很感谢任何形式的帮助!
<html>
<head>
<style>
.element{
width:200;
height:200;
-webkit-perspective: 800;
-webkit-transform-style: preserve-3d;
}
.element figure {
display: block;
height: 100%;
width: 100%;
position: absolute;
-webkit-backface-visibility: hidden;
border:1px solid yellow;
}
.element .front {
-webkit-border-radius:8px;
padding: 0px;
margin: 0px;
background-color:yellow;
z-index: 9870;
}
.element .back {
-webkit-border-radius:8px;
padding: 0px;
margin: 0;
-webkit-transform: rotateY( 180deg );
z-index: 0;
border: 1px solid red;
background-color:green;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="https://raw.github.com/pwhisenhunt/jquery.transform/master/jquery.transform.js"></script>
<script>
$(function(){ …Run Code Online (Sandbox Code Playgroud) 我正在尝试从Rails应用程序的JSON输出字符串中获取JSON对象.目前在JavaScript中我正在做:
data = "<%= @chromosomes.html_safe %>";
Run Code Online (Sandbox Code Playgroud)
但是,由于JSON对象的开头和结尾都有引号,因此它不会呈现为JSON对象.相反,它正在做类似的事情
data = "[{"name":"YHet","organism_id":"4ea9b90e859723d3f7000037"}]"
Run Code Online (Sandbox Code Playgroud)
有没有办法可以删除开头和结尾的引号,以便将对象视为数组而不是字符串?
我正在学习Backbone.js并遇到了一个奇怪的问题.我不确定这是否是实现这一点的正确方法.我试图在骨干视图和模型中包装一个jQuery UI Slider.但是,在滑块的滑动方法内部,我无法访问模型的值.任何帮助表示赞赏.这是我的代码:
var SliderView = Backbone.View.extend({
initialize: function(){
console.log("Creating the slider view...");
_.bindAll(this, 'render');
this.render();
},
render : function(){
console.log("Rendering the slider...");
$( "#slider-vertical" ).slider({
orientation: "vertical",
animate: true,
range: "min",
min: 0,
max: 50,
value: this.model.get('value'),
disabled: this.model.get('disabled'),
animate_if_programmed: true,
slide: function( ui ) {
console.log(model);
this.model.set('value', ui.value);
},
stop: function() {
this.check_bounds();
}
});
console.log("Finished rendering...");
}
})
var SliderModel = Backbone.Model.extend({
initialize : function(args) {
console.log("Creating the slider model...");
},
defaults : {
disabled : false, …Run Code Online (Sandbox Code Playgroud) 我想知道如何确定我何时在我阅读的文件的最后一行.我的代码看起来像
File.open(file_name).each do |line|
if(someway_to_determine_last_line)
end
Run Code Online (Sandbox Code Playgroud)
我注意到有一个file.eof?方法,但是如何在读取文件时调用该方法?谢谢!
我一直在使用backbone.js,并遇到了以下代码片段.
_(view.buttonViews).each(function(button) {
button.render();
});
Run Code Online (Sandbox Code Playgroud)
其中view.buttonViews是一个数组.如果我带走_()并拥有
view.buttonViews.each(function(button) {
button.render();
});
Run Code Online (Sandbox Code Playgroud)
然后我得到一个错误,每个都不是一个函数._()添加了什么?谢谢!
是否可以在将变量传递给Rails中的辅助方法之前传入该变量的值.
例如,我有一个base64_encode帮助方法,@ base_url只是在字符串文字中传递而不是被评估.
<%= base64_encode(#{@base_url} + '/helloworld.html') %>
Run Code Online (Sandbox Code Playgroud) 我已按照以下指南在 Mac OS 10.7.4 上设置 SSH 密钥。
https://help.github.com/articles/generate-ssh-keys
但由于某种原因,它不断提示我输入密码。如果我不指定密码,它不会提示我,但这不是我想要的。有没有办法缓存我的密码,这样我就不会在每次拉/推时都收到提示?