0

我正在学习对象文字符号,但我正在尝试,或者我认为我正在做的事情有点复杂。例如

我想要完成的是

  • 初始化我的对象
  • 存储一个 jquery 对象
  • 请求 JSON
  • 使用该 JSON 构建一些 html 并使用 promise

(免责声明,我希望你能原谅我的英语和我缺乏远见清楚地指出我的问题)

var objeto = objeto || (objeto = {
    jsonUrl:"/something",
    container:{},
    triggerContainer:{}, 
    property1:{},
    init:function(var0,var1){
        this.container = $(var0);
        this.triggerContainer = $(var1);
        // ignoring some details I proceed to set my event
        this.loader()
    },
    loader:function(){
        // Here my scope is objeto, so far so good
        // But I have create self because my scope is about to change, am I right?
        self = this;
        this.triggerContainer.on("click",function(){
            // now, I'm going to request the json making a promise
            promiseME = jQuery.getJSON(self.jsonUrl);
            promiseME.done(self.Build);
            // NOW, I did it in this way beacuse I think it looks a bit cleaner
            // Of course my problem come next
        });
    },
    build: function(data) {
        /*
          here it is, now this is scoped for the promise, and I want to use data 
          to build some html, but I want to append to objeto.container, and I don't 
          know how to access, and I did even know how to pass a refence with .done()

        */
    }

});

我很确定,我用这个结构搞砸了一些东西。也许我没有使用正确。如果是这样,你能解释一下我做错了什么吗

提前谢谢大家。

4

0 回答 0