English 中文(简体)
javascript asynchronous calls that populationing some property
原标题:javascript asynchronous calls that populate some property

我有一张 j印片,其中含有一些作为其财产的图象。 一俟该物体上台,就立即发出美国宇宙航空研究开发机构关于该财产居民身份的呼吁。

My view functions, at the same time, tries to read newly instantiated instances and tries to display this object. As expected, the AJAX call may not have finished by then yet, so it will not be able to read the right image url.

解决这个问题的一个解决办法是,在一定程度上利用美国宇宙航空研究开发机构发出的呼吁,即一旦完成就改变图像来源,但这正在对模型和观点造成许多依赖,而且我试图尽量使我的科索沃空间研究委员会分离,因此,我认为现在的职能只是将这个物体作为参数,读到所有的财产,并显示它。

使美国宇宙航空研究开发机构的同步点不是一种选择,因为我有许多这样的物体正在初步形成,只有一件事将当时展示,因此,使美国宇宙航空研究开发机构的所有呼吁都过于费钱。

解决这一问题有什么好办法? 观点功能是:

function displayObj(object) {
    var prop1 = object.getProp1();
    // this could be the image file that depends on AJAX result
    var prop2 = object.getProp2(); 
}

理想的情况是,我要把这项任务交给主人,这样,观察功能就不必担心物体的间隔期。 采集器可以通过检查图像是否存在,如果还不等待,那么只有在实际图像显示的情况下才能回去。 然而,阻碍等待会肯定会阻碍阿富汗复兴共和与民主军的进程,从而陷入僵局,不停的等待会让 get者返回,而观察功能将失去数据。

请阐明这种情况,或提出我可以组织我守则的其他办法。 非常感谢!

问题回答

d 略低于MVC的作用,使模型物体返回DOM代码><img> 反对。

// model object starts loading upon instantiation
var loader = new Loader();

// however the img tag is available immediately.
// the loader will update the src when ajax
// calls complete.
document.body.appendChild(loader.getImg());

由于你的评论,你建议采用“j Query”方法,将请求从ajax(>方法中退回。 例如,

var request = $.ajax("example.php");
request.done(notifyWhenSuccess);
request.fail(notifyWhenFailed);

酋长院提出的这一请求是共同法学会的“明智”模式的超级部分。 此外,由于它处于 j状态,因此不把亚克斯语称为一种观点,而是把它视为该模式的一部分。 利用<代码>done()方法更新模型,然后以数据变化的活动通知该观点。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签