【问题标题】:Breeze and Knockout not binding correctlyBreeze 和 Knockout 没有正确绑定
【发布时间】:2013-10-11 09:33:21
【问题描述】:

我正在尝试使用微风和淘汰赛的样本

manager.executeQuery(query).then(function(result){
    console.log(result);    
    ko.applyBindings(result);
}).fail(function(e) {
    console.log(e); 
     alert(e);  
});

在控制台中打印时。我在路径data.XHR.result.responseJSON 中得到两个对象,在data.results 中得到两个对象

但是在由于敲除绑定而创建的视图中,我将第二组值填充了​​两次。 (我在数据库中有两组值)

注意:如果我没有定义任何元数据,则此代码有效。问题在于我使用元数据的场景

元数据

var sample=sample||{};sample.metadata=
{
    "dataServices":[
        {
            "serviceName":"/sample",
            "hasServerMetadata":true,
            "jsonResultsAdapter":"webApi_default",
            "useJsonp":false
        }
    ],
    "structuralTypes":[
        {
            "shortName":"Employee",
            "autoGeneratedKeyType":"None",
            "defaultResourceName":"Employee",
            "dataProperties":[
                {
                    "name":"id",
                    "dataType":"MongoObjectId",
                    "isNullable":false,
                    "defaultValue":"",
                    "isPartOfKey":true,
                    "validators":[
                        {
                            "name":"required"
                        }
                    ]
                },
                {
                    "name":"name",
                    "dataType":"String",
                    "maxLength":100,
                    "validators":[
                        {
                            "maxLength":100,
                            "name":"maxLength"
                        }
                    ]
                },
                {
                    "name":"age",
                    "dataType":"String",
                    "maxLength":100,
                    "validators":[
                        {
                            "maxLength":100,
                            "name":"maxLength"
                        }
                    ]
                }
            ]
        }
       ], 
    "resourceEntityTypeMap":{
        "Employee":"Employee"
    }
};

【问题讨论】:

  • 听起来您用作主键的任何内容都未定义。你能展示你的模型吗?
  • 我猜肯定有ko.applyBindings(result.results)
  • @f_martinez 如果未定义元数据,它的工作原理
  • @PWKad 你是对的 :) 解决了它

标签: javascript binding knockout.js breeze knockout-2.0


【解决方案1】:

确保您有一个在模型中定义的主键并通过网络连接。如果您将这些值保留为 null,当微风将它们添加到缓存并看到键相同时,它们将相互覆盖。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-03
    • 2014-08-03
    • 2012-03-19
    • 2016-02-13
    • 2012-11-16
    • 2013-08-06
    • 2019-07-15
    • 1970-01-01
    相关资源
    最近更新 更多