I want this.item of an instance of the class to be filled by the data received through jQuery.post successor function. I am able to do this using some another user-defined function to set this.item with the data received.
我想要这个。通过jQuery接收的数据填充类的实例。职位的继任者函数。我可以使用另一个用户定义函数来设置这个。项目与收到的数据。
Question : Is there any way to set this.item inside the successor function of jQuer.post() without using any other user-defined functions ?
有什么方法可以设置这个吗?在jQuer.post()的继承函数中,不使用任何其他用户定义函数?
Following is the code snippet
下面是代码片段。
Inside Class Prototype function :-
内部类原型功能:-。
this.item = new Array();
jQuery.post("index.php?p=getdataitem", fileobj,function(item_str_data)
{
...
this.item = ....;
...
}
);
Thank You
谢谢你!
2 个解决方案
#1
2
You can do
你可以做
this.item = new Array();
var instance = this;
jQuery.post("index.php?p=getdataitem", fileobj,function(item_str_data)
{
...
instance.item = ....;
...
}
);
OR
或
this.item = new Array();
jQuery.ajax(
{url: "index.php?p=getdataitem",
context: this,
success: function(item_str_data)
{
...
this.item = ....;
...
}
}
);
#2
0
Try this:
试试这个:
var that = this;
var that.item = [];
function() {
jQuery.post("index.php?p=getdataitem", fileobj,function(item_str_data) {
...
that.item = ....;
...
});
}();
Because of the closure, the this
reference we copy (that
) should be available to the inner function of the post.
由于关闭,我们复制的这个引用应该可以用于post的内部功能。
#1
2
You can do
你可以做
this.item = new Array();
var instance = this;
jQuery.post("index.php?p=getdataitem", fileobj,function(item_str_data)
{
...
instance.item = ....;
...
}
);
OR
或
this.item = new Array();
jQuery.ajax(
{url: "index.php?p=getdataitem",
context: this,
success: function(item_str_data)
{
...
this.item = ....;
...
}
}
);
#2
0
Try this:
试试这个:
var that = this;
var that.item = [];
function() {
jQuery.post("index.php?p=getdataitem", fileobj,function(item_str_data) {
...
that.item = ....;
...
});
}();
Because of the closure, the this
reference we copy (that
) should be available to the inner function of the post.
由于关闭,我们复制的这个引用应该可以用于post的内部功能。