breeze默认使用observable和observableArrays包装属性,对吧?为什么在这种情况下不这样做?
var apiService = new breeze.DataService({
serviceName: 'api',
hasServerMetadata: false
});
var store = new breeze.MetadataStore({
namingConvention: breeze.NamingConvention.camelCase
});
var movieType = new breeze.EntityType({
shortName: 'Movie',
dataProperties: [
new breeze.DataProperty({
name: "id",
dataType: breeze.DataType.ID,
isNullable: false,
isPartOfKey: true
}),
new breeze.DataProperty({
name: "title",
dataType: breeze.DataType.String,
isNullable: false
})
]
});
store.addEntityType(movieType);
function Movie() {
var self = this;
self.isBeingEdited = false;
}
store.registerEntityTypeCtor('Movie', Movie);
var manager = new breeze.EntityManager({
dataService: apiService,
metadataStore: store
});
var favoriteMovie = movieType.createEntity({
id: 123,
title: "5th Element",
stars: ['Bruce Willis', 'Milla Yovovich']
});
manager.addEntity(favoriteMovie);
alert(favoriteMovie.title()); //errors favoriteMovie.title is not a function
答案 0 :(得分:2)
上面的代码很好。问题是我在breeze.js
之前加入knockout.js
包含的顺序非常重要。