如何将 `console.log` 与 Knockout 结合使用并使用 Knockoutjs 进行订阅?
我是第一次使用 Knockoutjs,由于无法在控制台中记录变量,因此在调试时遇到了麻烦。当我输入: Home.TwitterFeedComponent
时,我可以看到我的 JS 在控制台中正确加载,
我看到返回了一个 object
。如何将 console.log
与淘汰赛和订阅结合使用?
var Home = Home || {};
var inheriting = inheriting || {};
Home.TwitterFeedComponent = function(attributes) {
if (arguments[0] === inheriting)
return;
Home.OnScreenComponent.call(this, attributes);
var component = this;
var recent_tweets = ko.observableArray();
var url = 'https://twitter.com/search.json?callback=?';
this.attributes.twitter_user_handle.subscribe(function(value) {
var twitter_parameters = {
include_entities: true,
include_rts: true,
from: value,
q: value,
count: '3'
}
result = function getTweets(){
$.getJSON(url,twitter_parameters,
function(json) {
console.log(json)
});
}
console.log(twitter_parameters);
});
};
Home.TwitterFeedComponent.prototype = new Home.OnScreenComponent(inheriting);
Home.TwitterFeedComponent.prototype.constructor = Home.TwitterFeedComponent;
I'm using Knockoutjs for the first time and I'm having trouble debugging because of my inability to log variables in console. I can see that my JS is loading properly in console, when I enter:
Home.TwitterFeedComponent
I see an object
returned. How do I use console.log
in conjunction with knockout and subscribe?
var Home = Home || {};
var inheriting = inheriting || {};
Home.TwitterFeedComponent = function(attributes) {
if (arguments[0] === inheriting)
return;
Home.OnScreenComponent.call(this, attributes);
var component = this;
var recent_tweets = ko.observableArray();
var url = 'https://twitter.com/search.json?callback=?';
this.attributes.twitter_user_handle.subscribe(function(value) {
var twitter_parameters = {
include_entities: true,
include_rts: true,
from: value,
q: value,
count: '3'
}
result = function getTweets(){
$.getJSON(url,twitter_parameters,
function(json) {
console.log(json)
});
}
console.log(twitter_parameters);
});
};
Home.TwitterFeedComponent.prototype = new Home.OnScreenComponent(inheriting);
Home.TwitterFeedComponent.prototype.constructor = Home.TwitterFeedComponent;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在您的代码中没有看到问题,但是如果您想记录“Observables”,则必须按如下方式记录:
I don't see the problem in your code, but if you want to log 'Observables', you have to log it as follows:
我有点不清楚问题的确切范围 - 但是,如果像我一样,这个问题是针对在 HTML 中使用
console.log
的。下面是一组可能有帮助的代码:
该代码只是将
foreach
内的一个项目记录到控制台。希望这有帮助!
I'm a little unclear as to the exact scope of the question -- however, if like mine, this question is directed toward the use of
console.log
within your HTML.Here is a little set of code that may help:
This code simply logs an item inside of a
foreach
to the console.Hope this helps!