小编Tor*_*ups的帖子

使用jQuery查找给定表中的TR元素数

我已经看过几个关于如何寻找孩子等的例子,但由于某种原因,我无法得到这个......来自SO社区的任何帮助?

以下是我目前在代码中的"尝试" -

var trCount = $("#table> tr").size();

jquery

4
推荐指数
1
解决办法
1万
查看次数

如何在视图控制器中添加和检索NSDictionary中的数据

我正在尝试使用NSDictionary在我的视图控制器中缓存一些图像,但我没有太多运气.

对于初学者我的.h看起来像这样

...
  NSDictionary *images;
}

@property (nonatomic, retain) NSDictionary *images;
Run Code Online (Sandbox Code Playgroud)

在我的.m我合成属性并尝试添加图像如下:

[self.images setValue:img forKey:@"happy"];
Run Code Online (Sandbox Code Playgroud)

后来我试图按键抓取图像

UIImage *image = [self.images objectForKey:@"happy"];
    if (!image) {
      NSLog(@"not cached");
    }else {
      NSLog(@"had cached img %@", image);
    }
Run Code Online (Sandbox Code Playgroud)

然而每次我NSLog字典它都是空的.如果我@synthesize属性我应该准备好开箱即用?或者我没有正确地将它添加到字典中?

先感谢您

objective-c nsdictionary

4
推荐指数
1
解决办法
5080
查看次数

如何在objective-c中使用sqlite3_exec将UIImage作为blob插入

我试图将sqlite中的一些图像缓存为nsdata,当我尝试使用sqlite3_exec和原始SQL字符串(作为NSString)插入字节数组时,我遇到了问题

NSData *imgData = UIImagePNGRepresentation(img);
NSString* sql = [NSString stringWithFormat:@"INSERT INTO persistedimg (imgx,idvalx) VALUES (%@,'%@')", imgData, idValue];
rc = sqlite3_exec(db, [sql UTF8String], callbackFunction, (void*)contextObject, &zErrMsg);
Run Code Online (Sandbox Code Playgroud)

但是上面的问题是我将NSData直接添加到sql字符串而不是字节.

我想做这样的事情

... [imgData bytes], [imgData length]
Run Code Online (Sandbox Code Playgroud)

但是因为我没有使用典型的"_bind_blob"方法,所以我不知道如何用原始字符串做

更新

我正在使用一个我想要粘贴的包装器,只需编写一个新方法来支持图像插入/查询命令

到目前为止,下面是我的整个包装类

**

#import "SQLiteAccess.h"
#import <sqlite3.h>

@implementation SQLiteAccess

+ (NSString *)pathToDB {
    NSString *dbName = @"test123";
  NSString *originalDBPath = [[NSBundle mainBundle] pathForResource:dbName ofType:@"db"];
  NSString *path = nil;
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *appSupportDir = [paths objectAtIndex:0];
  NSString *dbNameDir = [NSString stringWithFormat:@"%@/test123", appSupportDir];
  NSFileManager …
Run Code Online (Sandbox Code Playgroud)

sqlite objective-c nsdata

4
推荐指数
1
解决办法
9222
查看次数

如何比较java日期中的那一天?

我想在昨天和今天之间做一个简单的日期比较

if (yesterday.before(today)) {
 ...
}
Run Code Online (Sandbox Code Playgroud)

问题是,使用before方法,即使只有几秒钟的差异,我也会评估为真.我怎么可以只比较一天(因为我只想将它评估为真如果它是前一天(应该忽略分钟/秒)

先感谢您

java date

4
推荐指数
2
解决办法
1万
查看次数

如何在放入java HashMap时避免重新排序项目

我正在创建一个新的Map并将字符串推入其中(没什么大不了的) - 但我注意到随着地图的增长,字符串正在被重新排序.是否可以停止这种重新排序,以便地图中的项目保留所放置的顺序?

Map<String,String> x = new HashMap<String, String>();
x.put("a","b");
x.put("a","c");
x.put("a","d");

x.put("1","2");
x.put("1","3");
x.put("1","4");

//this shows them out of order sadly...
for (Map.Entry<String, String> entry : x.entrySet()) {
    System.out.println("IN THIS ORDER ... " + entry.getValue());
}
Run Code Online (Sandbox Code Playgroud)

java hashmap

4
推荐指数
3
解决办法
6099
查看次数

如何使用动作帮助器访问ember 1.0 pre中的特定上下文

在我的余烬视图中,我希望在每个人中获取该人并将其传递给动作但是目前我只在路由器中获得了一个jquery事件(好奇,如果这现在在1.0版本中免费绑定到上下文中)

模板

<script type="text/x-handlebars" data-template-name="person">
       {{#each person in controller}}
          <li> 
          {{person.username}}
          <input type="submit" value="delete" {{action removePerson person}}/>                   
          </li>
       {{/each}}
</script>
Run Code Online (Sandbox Code Playgroud)

路由器w /我希望调用w/person上下文的方法

Router: Ember.Router.create({
  root: Ember.Route.extend({
    index: Em.Route.extend({
      route: '/',
      removePerson: function(router, context) {
        router.get('personController').removePerson(context);
      },
Run Code Online (Sandbox Code Playgroud)

控制器更详细

PersonController: Ember.ArrayController.extend({
      content: [],                                                                               
      addPerson: function (username) {
        var person = PersonApp.Person.create({
          username: username
        });
        this.pushObject(person);
      },
      removePerson: function (person) {
        this.removeObject(person);
      }
    }),
Run Code Online (Sandbox Code Playgroud)

ember.js

4
推荐指数
1
解决办法
513
查看次数

如何使用ember.js进行类似的过滤

我在ember pre 1.0中有一个简单的ArrayController,发现如果过滤器找到给定属性的完全匹配,我可以将列表缩小,但我似乎找不到的是如何使用过滤器进行"喜欢"查询.

如果我用一个用户搜索一个数组,下面的内容是有用的......

filtered = ['id', 'username'].map(function(property) {
  return self.get('content').filterProperty(property, filter);
});
Run Code Online (Sandbox Code Playgroud)

...并且一些用户具有相同的用户名.例如=>如果我通过"smith"搜索/过滤它将返回两个记录,因为"username"属性与"smith"完全匹配

如何更改此地图功能以使用类似的样式查询,因此当我键入单词"sm"时,它仍然可以找到这两个记录

这是jsfiddle显示我在上面显示的过滤器http://jsfiddle.net/Rf3h8/

先感谢您

ember.js

4
推荐指数
1
解决办法
3077
查看次数

如何正确执行ember运行循环中的Ember.RSVP.all

我正试图在Ember.RSVP.all中执行一个承诺

App.Foo = Ember.Object.create({
    bar: function() {
        var configuration = ajaxPromise("/api/configuration/", "GET");
        Ember.RSVP.all([configuration]).then(function(response) {
            //do something with the response in here
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

但是因为我的集成测试模拟xhr w/out一个运行循环,测试失败并出现预期错误"你已经打开测试模式,这会禁用运行循环'自动运行"

所以我用一个简单的ember.run包装了RSVP

App.Foo = Ember.Object.create({
    bar: function() {
        var configuration = ajaxPromise("/api/configuration/", "GET");
        Ember.run(function() {
            Ember.RSVP.all([configuration]).then(function(response) {
                //do something with the response in here
            });
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

但我仍然因为一些奇怪的原因而得到错误.注意 - 如果我稍后运行它没关系(这不会工作,因为我需要执行异步代码以使此测试正常工作)

App.Foo = Ember.Object.create({
    bar: function() {
        var configuration = ajaxPromise("/api/configuration/", "GET");
        Ember.run.later(function() {
            Ember.RSVP.all([configuration]).then(function(response) {
                //do something with the response in here
            });
        }); …
Run Code Online (Sandbox Code Playgroud)

ember.js rsvp.js

4
推荐指数
1
解决办法
4651
查看次数

如何在Ember.RSVP.hash之后注册自定义回调

我有一条路线,使用RSVP就可以实现两种不同的承诺

model: function() {
  return Ember.RSVP.hash(function() {
    stuff: App.Thing.find(),
    other: this.store.find('appointments', {day: day})    
  });
}
Run Code Online (Sandbox Code Playgroud)

挑战在于我有一个自定义函数,我在上面显示的第二个promise的"then"中绑定/调用.当回调发生在另一个使用RSVP的承诺时,我如何调用它?

这是今天的自定义回调(不在RSVP.hash内部)

    function bindContextAndGenerateAvailable(employee, other, appointments) {
        return function(filteredAppointments) {
            //will take the filtered collection and do something w/ it
            //to populate the bound appointments array passed in
        }
    }

    var appointments = Ember.A([]);
    this.store.find('appointment', {day: day}).then(function(response) {
        Ember.RSVP.all(response.getEach('employee')).then(function(empls){
          var filtered = response.filterBy('employee.id', employee);
          Ember.RSVP.resolve(filtered).then(bindContextAndGenerateAvailable(employee, other, appointments));
        });
    });
    return appointments;
Run Code Online (Sandbox Code Playgroud)

ember.js rsvp.js

4
推荐指数
1
解决办法
2287
查看次数

如何为服务以外的东西创建注入助手?

https://github.com/emberjs/ember.js/blob/5fd2d035b30aa9ebfe73de824b3b283ec8e589cc/packages/ember-runtime/lib/system/service.js#L31

在我上面的参考文献中,ember-core团队导入了这个createInjectionHelper并使用它来添加一个干净/简单的api来注入像这样的服务

App.ApplicationRoute = Ember.Route.extend({
  authManager: Ember.inject.service('auth'),
  model: function() {
    return this.get('authManager').findCurrentUser();
  }
});
Run Code Online (Sandbox Code Playgroud)

如何为非服务创建这样的东西?

ember.js

4
推荐指数
1
解决办法
760
查看次数

标签 统计

ember.js ×5

java ×2

objective-c ×2

rsvp.js ×2

date ×1

hashmap ×1

jquery ×1

nsdata ×1

nsdictionary ×1

sqlite ×1