将对象数据传递给jQuery.后继函数
Passing Object data to jQuery.post successor function
我要这个。类实例的项将由通过jQuery接收到的数据填充。后继函数。我可以使用另一个用户定义的函数来设置它。项,包含接收到的数据。
问题:有没有办法设置这个。项目在jquery .post()的后继函数没有使用任何其他用户定义的函数?
下面是代码片段内部类原型函数:-
this.item = new Array();
jQuery.post("index.php?p=getdataitem", fileobj,function(item_str_data)
{
...
this.item = ....;
...
}
);
谢谢
你可以做
this.item = new Array();
var instance = this;
jQuery.post("index.php?p=getdataitem", fileobj,function(item_str_data)
{
...
instance.item = ....;
...
}
);
或
this.item = new Array();
jQuery.ajax(
{url: "index.php?p=getdataitem",
context: this,
success: function(item_str_data)
{
...
this.item = ....;
...
}
}
);
试试这个:
var that = this;
var that.item = [];
function() {
jQuery.post("index.php?p=getdataitem", fileobj,function(item_str_data) {
...
that.item = ....;
...
});
}();
由于闭包,我们复制的this
引用(that
)应该对post的内部函数可用。
相关文章:
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 如何在JQuery函数中定义一个值,然后调用另一个函数并使用该值
- 如何从jquery函数返回变量
- 如何将具有文本类型值的var放入jQuery函数中
- Jquery函数在错误的时间提交
- 锚链接无法使用.slideUp jquery函数
- 重新分解jQuery函数
- 如何在视图模型contet更新更新上调用Jquery函数
- 如何向这个javascript/jquery函数添加参数
- 添加类来触发jquery函数
- 更改智能表中的页面将停止JQuery函数的工作
- 使用每500ms运行一次的jquery函数是个好主意吗
- jQuery函数不能只在一个页面上工作
- 如何将jquery函数链接到vanilla选择器
- 仅在小型设备上调用jQuery函数
- 如何将jquery函数仅应用于大屏幕
- 奇怪的jquery函数行为
- Backbone listenTo不将jquery函数作为处理程序进行激发
- 在jquery函数内部设置来自jquery函数的var;t运行
- 从Jquery函数中获取一个变量