我在 Backbone 中定义了一个模型和集合,如下所示:
$(document).ready(function () {
DeviceModel = Backbone.Model.extend({
urlRoot: '/ajax/mvcDevices',
validationRules: {
name: [{ rule: 'required'}],
mac: [
{ rule: 'required' },
{ rule: 'isMacAddress' }
],
speed: [{ rule: 'required'}]
},
preprocess: {
name: ['clean', 'trim'],
speed: ['clean', 'trim']
}
});
DeviceCollection = Backbone.Collection.extend({
url: '/ajax/mvcDevices',
Model: DeviceModel
});
});
但是,当在 Collection 中使用这些模型时,列出的自定义字段都没有定义。我在这里错过了什么?