我正在尝试绑定两个提交事件,并阻止第二个事件.
例:
$('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)
什么是最好的方式扩展的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) (对不起,如果先前查询过,我没找到它)
我曾经检查过对象和方法是否存在并以这种方式调用它:
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)
我想知道什么是最安全和最清晰的代码风格.
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中.我不确定问题是什么?
javascript ×2
apex-code ×1
backbone.js ×1
int ×1
java ×1
jquery ×1
salesforce ×1
submit ×1
typeof ×1