小编Mar*_*iry的帖子

Jquery preventDefault对许多提交都不起作用

我正在尝试绑定两个提交事件,并阻止第二个事件.

例:

$('form').submit(function(event){ 
    alert(1); 
    //if some condition cut the submit events
    event.preventDefault();
    return false;
});

$('form').submit(function(){ 
    alert(2); 
    return false;    
});
Run Code Online (Sandbox Code Playgroud)

这是http://jsfiddle.net/da3aB/的例子

jquery submit preventdefault

3
推荐指数
1
解决办法
1453
查看次数

扩展Backbone模型保存

什么是最好的方式扩展model.save方法

我需要添加新方法将相同的数据发布到后端.ie:played方法应该请求(通过POST)apiurl/model/:id/played

例如:

var Game = Backbone.Model.Extend({
   baseUrl: '/games/',
   played: function(){
      this.url = this.baseUrl + this.id + '/played' 
      this.save();
   }
}); 

var game = new Game({id:3234});  //is only an example, instances are created before previuosly
game.played();
Run Code Online (Sandbox Code Playgroud)

这种方式有效,但请求是GET.此外,如果这save()不会在请求中发送所有属性,那将是完美的.

添加信息: 由于我必须与跨域api进行交互,因此我扩展了同步方法以使用JSONP.此外,我添加了一些安全说明.

//backbone sync
Backbone._sync = Backbone.sync;
Backbone.sync = function(method, model, options) {
    //network
    options.timeout = 10000;
    options.dataType = "jsonp";  
    //security
    if(_conf.general.accessToken){
        var ak = _conf.general.accessToken, 
        url = model.url,
        linker = url.indexOf('?') === …
Run Code Online (Sandbox Code Playgroud)

javascript backbone.js

3
推荐指数
1
解决办法
4333
查看次数

检查对象属性和调用方法的更好方法

(对不起,如果先前查询过,我没找到它)

我曾经检查过对象和方法是否存在并以这种方式调用它:

 obj && obj.method && obj.method()
Run Code Online (Sandbox Code Playgroud)

但是,我怀疑在某些情况下这会给IE带来一些麻烦..

我需要使用它typeof undefined/function/object 吗?

 typeof obj === 'object' && typeof obj.method === 'function' && obj.method()
Run Code Online (Sandbox Code Playgroud)

我想知道什么是最安全和最清晰的代码风格.

javascript typeof

3
推荐指数
1
解决办法
58
查看次数

保存错误:无效的类型:int

public int getSelected2()
{
    //selectedAssets.clear(); //
    for(assetswrapper accwrapper : assetsList)
        if(accwrapper.selected == true)
            selectedAssets.add(accwrapper.acc);
    int a;
    a = selectedAssets.size();
    return a;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译以下代码时,我收到此错误:

保存错误:Inavlid类型:int.

这是在Salesforce中.我不确定问题是什么?

java int salesforce apex-code

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