演示小提琴(有问题)http://jsfiddle.net/mjmitche/UJ4HN/19/
我有一个像这样定义的集合
var Friends = Backbone.Collection.extend({
model: Friend,
localStorage: new Backbone.LocalStorage("friends-list")
});
Run Code Online (Sandbox Code Playgroud)
据我所知,这就是我需要做的就是让本地存储工作(除了将它包含在backbone.js之下)
有一件事我不确定,名称"friends-list"是否必须与DOM元素对应?我正在尝试保存"friends-list",所以我称之为在本地存储中,但localstorage似乎不需要传递类或id.
这是一个小提琴,你可以看到我正在尝试做什么http://jsfiddle.net/mjmitche/UJ4HN/19/
在我的本地网站上,我正在添加几个朋友,刷新页面,但朋友们没有重新出现.
更新
我在我的本地网站上的代码中也完成了以下操作
console.log(Backbone.LocalStorage);
Run Code Online (Sandbox Code Playgroud)
它并没有抛出错误.
我尝试调试
我在window.AppView中尝试了这段代码(取自另一个SO答案)但控制台中没有任何内容.
this.collection.fetch({}, {
success: function (model, response) {
console.log("success");
},
error: function (model, response) {
console.log("error");
}
})
Run Code Online (Sandbox Code Playgroud) 我正在做一些命令行执行,我在这篇博客文章中system或IO.popen在文件中学到了,并且我遇到了错误.
为什么反引号出现,它意味着什么,以及如何继续?请解释.
system('./err.rb')
-bash: syntax error near unexpected token `'./err.rb''
Run Code Online (Sandbox Code Playgroud)
类似地,当我跑IO.popen:
output = IO.popen('./err.rb')
-bash: syntax error near unexpected token `('
Run Code Online (Sandbox Code Playgroud) 根据这个StackOverflow的答案,jQuery.fn是什么意思?,fn属性in jQuery.fn.jquery是prototype属性的别名.我假设在完整代码如下的这两种方法中这是相同的
$.fn.map = function() 和 $.fn.tweets = function()
我的问题是,例如,如果$ .fn.tweets使用原型来创建推文方法,那么这段代码是否$('tweets').tweets 会调用它...
var $tweets = $('#tweets').tweets({
query: buildQuery(approxLocation),
template: '#tweet-template'
});
Run Code Online (Sandbox Code Playgroud)
如果是这样,它将如何触发该方法.例如,仅仅在文件加载上创建变量是否会触发该函数,其中包含其他方法,即查询?谢谢你的帮助
完整的方法代码
$.fn.map = function(method) {
console.trace();
console.log(method);
if (method == 'getInstance') {
console.log("fn.map");
return this.data('map');
}
return this.each(function() {
var $this = $(this);
var map = $this.data('map');
if (map && MyMap.prototype[method]) {
map[method] (Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
var options …Run Code Online (Sandbox Code Playgroud) 在此链接中,Mozilla以下列方式解释了"this"引用:
通常,
this在当前作用域中绑定的对象由当前函数的调用方式决定,在执行期间不能通过赋值来设置,并且每次调用函数时它都可以不同.
在正常情况下,我理解this它的参考如何变化.
Pro JavaScript Design Patterns一书中提到了以下关于词法范围的内容
JavaScript也是词法范围的,这意味着函数在定义它们的范围内运行,而不是在它们执行的范围内运行.
所以'this'取决于当前函数的调用方式,而词法范围意味着函数在定义它们的范围内运行.
我的问题是,它可以this成为词法范围的一部分,如果是这样,我如何理解这取决于如何调用当前函数的事实,而词法范围将函数限制在它们被定义的范围内.
这里有一篇为期两年的博客文章,解释了如何修复"你必须首先安装开发工具"的错误'Nokogiri附带的错误,如果你在安装RVM后升级到Mountain Lion就会出现这个问题.在博客文章中他说你必须做
rvm update head
rvm --force install 1.9.2
gem install bundle
## in your rails app
bundle
Installing nokogiri (1.4.2) with native extensions
...
Run Code Online (Sandbox Code Playgroud)
rvm update head现在已改为rvm get head.然而,在那之后我一味地做了
rvm --force install 1.9.2
Run Code Online (Sandbox Code Playgroud)
并收到此错误消息
rvm --force install 1.9.2
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.8/x86_64/ruby-1.9.2-p320.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
The provided compiler '/usr/bin/gcc' is …Run Code Online (Sandbox Code Playgroud) 在尝试从书中学习Objective C时,我希望能够运行一些代码片段,如...
NSString *str = @"Hello, world!";
NSLog(@"Retain count is %d", [str retainCount]);
Run Code Online (Sandbox Code Playgroud)
在Ruby中我只是把它放在一个snippet.rb文件中并ruby snippet.rb从终端运行.JavaScript有jsfiddle.net.使用目标c有同样简单的方法吗?
我刚刚在Mac上安装了Middleman(OS 10.8.2),但无法生成新项目.我安装了Xcode.谁能告诉我我可能做错了什么?
$ middleman init moi
-bash: middleman: command not found
Run Code Online (Sandbox Code Playgroud)
$ gem list
middleman (3.0.12)
middleman-core (3.0.12)
middleman-more (3.0.12)
middleman-sprockets (3.0.9)
Run Code Online (Sandbox Code Playgroud)
$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
Run Code Online (Sandbox Code Playgroud)
我正在使用rbenv.这是我的道路:
/Users/me/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/Users/me/downloads/mongodb/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Run Code Online (Sandbox Code Playgroud) 我的数据库中有很多用户使用这些属性,但是,我只想要每个用户的电子邮件地址
#<User id: 1, email: "email@yahoo.com", encrypted_password: "", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2012-09-03 09:14:01", updated_at: "2012-09-03 09:14:01", name: nil, confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, unconfirmed_email: nil, opt_in: nil, invitation_token: nil, invitation_sent_at: nil, invitation_accepted_at: nil, invitation_limit: nil, invited_by_id: nil, invited_by_type: nil>,
Run Code Online (Sandbox Code Playgroud)
在控制台中,我做到了
u = User.all
Run Code Online (Sandbox Code Playgroud)
它打印了所有用户及其属性.
现在,要获取每个我尝试过的电子邮件地址
u.each do |f|
f.email
end
Run Code Online (Sandbox Code Playgroud)
但它只是再次打印了整个用户列表及其所有属性.
任何人都可以告诉我如何打印所有用户的电子邮件地址列表,省略其他属性.
我有一个充当计时器的按钮。当它通过更改按钮标题更新时间时,按钮会闪烁。但是,如果我将计时器放在没有按钮的标题视图中并更新 headerLabel 的文本,它不会闪烁。我可以对按钮做些什么,让它在更新标题时不闪烁吗?
-(void)countdownTime:(NSTimer *)timer
{
self.minutes = self.secondsRemaining / 60;
self.stringMinutes = [NSString stringWithFormat:@"%i", self.minutes];
self.seconds = self.secondsRemaining - (self.minutes * 60);
self.stringSeconds = [NSString stringWithFormat:@"%i", self.seconds];
if (self.seconds < 10) self.stringSeconds = [NSString stringWithFormat:@"0%i", self.seconds];
self.time = [NSString stringWithFormat:@"%@:%@", self.stringMinutes, self.stringSeconds];
self.secondsRemaining += 1;
[self.delegate updateTimerButton:self.time];
}
Run Code Online (Sandbox Code Playgroud)
按钮闪烁
- (void) updateTimerButton:(NSString *) sender {
[self.timerButton setTitle: [NSString stringWithFormat:@"%@", sender] forState: UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
标题视图不闪烁
[self.headerLabel setText: [NSString stringWithFormat:@"%@", self.time]];
Run Code Online (Sandbox Code Playgroud) 我有一个date-filter我在Ember应用程序中使用的组件,它只适用于初始渲染,而不是页面重新加载,或者即使我保存文件(触发应用程序进行实时更新).
在我的应用程序的主模板中,我像这样渲染日期过滤器,传递一个unix时间戳
{{date-filter unixepoch=item.date}}
Run Code Online (Sandbox Code Playgroud)
然后,在 components/date-filter.js,我使用一个被调用的计算属性timeConverter来将unix epoch更改为根据用户选择的语言格式化的时间字符串,然后在我的templates/components/date-filter.hbs文件中我{{timeConverter}}显示结果
timeConverter: function(){
//step 1: get the epoch I passed in to the component
var epoch = this.get('unixepoch');
//step 2: create a human readable date string such as `Jun 29, 2015, 12:36PM`
var datestring = new Date(epoch)
//do language formatting --code omitted as the problem is with step2
}
Run Code Online (Sandbox Code Playgroud)
如果我刷新页面甚至保存文件step 2,那就是失败(返回invalid date).它始终在第一次调用此组件时返回正确的日期字符串.即使我new Date(epoch)在父组件中,并尝试将结果传递给此组件(进行外语格式化),我遇到了同样的问题.
问题:我怎样才能弄清楚新日期(纪元)内发生了什么,或者它是否与组件有关?
ruby ×4
javascript ×3
objective-c ×2
backbone.js ×1
bash ×1
ember.js ×1
ios ×1
jquery ×1
middleman ×1
rbenv ×1
rvm ×1