2
votes

I was trying a sample using breeze and knockout

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

While printing in the console. I'm getting two objects in the path data.XHR.result.responseJSON and two objects in data.results

But in the view created as a result of knockout binding I'm getting the second set of value populated two times. (I have two set of values in the db)

NOTE: This code is working if I havent defined any metadata. Issue is in the scenario where I use metadata

metadata

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"
    }
};
1
Sounds like whatever you are using as a primary key is coming across the wire undefined. Can you show your model? - PW Kad
There must be ko.applyBindings(result.results) I guess. - Rango
@f_martinez Its working if metadata is not defined - Okky
@PWKad You were right :) solved it - Okky

1 Answers

2
votes

Make sure that you have a primary key that is defined in your model and coming across the wire. If you leave those values as null they will overwrite each other when breeze adds them to the cache and sees the keys are the same.