【问题标题】:Reload knockout js view after ajax - json loadedajax - json加载后重新加载淘汰赛js视图
【发布时间】:2013-12-30 15:27:30
【问题描述】:

我正在做淘汰赛,

这是静态示例:

static fiddle

数组改变时刷新但是;

这是动态示例:

dynamic fiddle

这不是刷新,也不是在 init 中加载。

json 部分在这里;

      $.getJSON( "/echo/json/")
      .done(function( json ) {
         $.each(json.data.data, function(i, item){
            console.log(item.name); // json Item
            data.push(JSON.stringify(item)); // I push the json item in array
            console.log(data); //array
          })        
  })

谢谢大家

【问题讨论】:

    标签: ajax json knockout.js mapping


    【解决方案1】:

    看这里:

    http://jsfiddle.net/KU9t5/4/

    您的 getAttachments() 函数应该只更新可观察数组的内容:

    ajax 调用:

    $.post( "/echo/json/", "{}")
          .done(function( json ) {
              self.attachments([]);
             $.each(data, function(i, item){
                console.log(item.name); // json Item
    
                self.attachments.push(item);
                console.log(self.attachments()); //array
            });        
          })
          .fail(function( jqxhr, textStatus, error ) {
            var err = textStatus + ", " + error;
            console.log( "Request Failed: " + err );
        });
    

    刷新()函数:

    self.refresh = function() {
        self.getAttachments();
      //self.attachments(self.getAttachments());
      //ko.mapping.fromJS(self.getAttachments(), self.attachments);
      console.log("attachments:" + self.attachments());
    
    }
    

    【讨论】:

    • 感谢您的帮助,我只需要“推送”功能
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    • 2018-11-08
    • 2014-01-30
    • 2014-05-13
    • 2017-08-26
    • 2015-09-07
    • 2017-12-11
    相关资源
    最近更新 更多