admin管理员组文章数量:1026202
In my controller I'm passing in a parameter called 'url' to a view. This is passed successfully into the initialize function. Next when I create my model I would like to pass the same parameter into the model to use as the rooturl.
Below is what I have tried but I got the following error message:
A "url" property or function must be specified
This seems like the parameter is not being passed to the model (undefined) or I'm not calling it correctly in the model. What I'm I doing wrong here?
Note: console.log(options.url) in the initialize function view confirms the parameter is passed successfully from the controller to the view, the issues is from the view to the model where it is undefined.
Controller:
var myview = new NewView({
url:"api/"
})**
View:
var myview = Backbone.Marionette.ItemView.extend({
initialize: function (options) {
this.url = options.url;
this.model.fetch();
},
model: new myModel({
url: this.url
}),
myModel:
var myModel = Backbone.Model.extend({
urlRoot: function(){ return this.get('url') }
});
In my controller I'm passing in a parameter called 'url' to a view. This is passed successfully into the initialize function. Next when I create my model I would like to pass the same parameter into the model to use as the rooturl.
Below is what I have tried but I got the following error message:
A "url" property or function must be specified
This seems like the parameter is not being passed to the model (undefined) or I'm not calling it correctly in the model. What I'm I doing wrong here?
Note: console.log(options.url) in the initialize function view confirms the parameter is passed successfully from the controller to the view, the issues is from the view to the model where it is undefined.
Controller:
var myview = new NewView({
url:"api/"
})**
View:
var myview = Backbone.Marionette.ItemView.extend({
initialize: function (options) {
this.url = options.url;
this.model.fetch();
},
model: new myModel({
url: this.url
}),
myModel:
var myModel = Backbone.Model.extend({
urlRoot: function(){ return this.get('url') }
});
Share
Improve this question
asked Nov 15, 2013 at 15:31
PrometheusPrometheus
33.7k58 gold badges174 silver badges311 bronze badges
2 Answers
Reset to default 5You are trying to fetch your model with an empty url.
When you call:
initialize: function (options) {
this.url = options.url;
this.model.fetch();
}
fetch
here, you don't have the url for the model. So, you could do:
initialize: function (options) {
this.url = options.url;
this.model.set({url: this.url});
this.model.fetch();
}
When writing
model: new myModel({
url: this.url
}),
the view is not yet initialized
You can instantiate the model in the view's initialize method
initialize: function (options) {
this.url = options.url;
this.model = new myModel({
url: this.url
})
this.model.fetch();
},
In my controller I'm passing in a parameter called 'url' to a view. This is passed successfully into the initialize function. Next when I create my model I would like to pass the same parameter into the model to use as the rooturl.
Below is what I have tried but I got the following error message:
A "url" property or function must be specified
This seems like the parameter is not being passed to the model (undefined) or I'm not calling it correctly in the model. What I'm I doing wrong here?
Note: console.log(options.url) in the initialize function view confirms the parameter is passed successfully from the controller to the view, the issues is from the view to the model where it is undefined.
Controller:
var myview = new NewView({
url:"api/"
})**
View:
var myview = Backbone.Marionette.ItemView.extend({
initialize: function (options) {
this.url = options.url;
this.model.fetch();
},
model: new myModel({
url: this.url
}),
myModel:
var myModel = Backbone.Model.extend({
urlRoot: function(){ return this.get('url') }
});
In my controller I'm passing in a parameter called 'url' to a view. This is passed successfully into the initialize function. Next when I create my model I would like to pass the same parameter into the model to use as the rooturl.
Below is what I have tried but I got the following error message:
A "url" property or function must be specified
This seems like the parameter is not being passed to the model (undefined) or I'm not calling it correctly in the model. What I'm I doing wrong here?
Note: console.log(options.url) in the initialize function view confirms the parameter is passed successfully from the controller to the view, the issues is from the view to the model where it is undefined.
Controller:
var myview = new NewView({
url:"api/"
})**
View:
var myview = Backbone.Marionette.ItemView.extend({
initialize: function (options) {
this.url = options.url;
this.model.fetch();
},
model: new myModel({
url: this.url
}),
myModel:
var myModel = Backbone.Model.extend({
urlRoot: function(){ return this.get('url') }
});
Share
Improve this question
asked Nov 15, 2013 at 15:31
PrometheusPrometheus
33.7k58 gold badges174 silver badges311 bronze badges
2 Answers
Reset to default 5You are trying to fetch your model with an empty url.
When you call:
initialize: function (options) {
this.url = options.url;
this.model.fetch();
}
fetch
here, you don't have the url for the model. So, you could do:
initialize: function (options) {
this.url = options.url;
this.model.set({url: this.url});
this.model.fetch();
}
When writing
model: new myModel({
url: this.url
}),
the view is not yet initialized
You can instantiate the model in the view's initialize method
initialize: function (options) {
this.url = options.url;
this.model = new myModel({
url: this.url
})
this.model.fetch();
},
本文标签: javascriptbackbone passing parameters to a model urlStack Overflow
版权声明:本文标题:javascript - backbone passing parameters to a model url - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745629888a2160096.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论