是否可以获得数据(模型)实例绑定的相应元素(或元素)?
例如,我在ViewModel属性中有一个'Person'对象存储数组.
我将ViewModel绑定到呈现它的视图,例如:
<div class="people" data-bind="template: { foreach: people }">
<a href="#" class="person" data-bind="text: name"></a>
</div>
Run Code Online (Sandbox Code Playgroud)
然后我通过jQuery绑定一些事件处理程序:
$container.on('click', '.person', function(e){
e.preventDefault();
self.showPerson( ko.dataFor(this) );
});
Run Code Online (Sandbox Code Playgroud)
在我的showPerson方法中,我会保存对模型的引用.我/可能/也是一个保存对元素的引用,但我不想,如果我没有.
self.showPerson = function(person) {
// can i get the corresponding element from the 'person' model?
};
Run Code Online (Sandbox Code Playgroud)
有人有任何想法吗?
我正在使用它google.maps.places.AutocompleteService来获取场所搜索的建议,但我无法对一些预测进行地理编码.
这方面的一个例子:当我搜索" 风暴河口 "时,我得到的预测之一是" 南非风暴河口休息营 ",但这个地址无法进行地理编码以获得格子/经度,例如:http ://maps.googleapis.com/maps/api/geocode/json地址=风暴%20River%20Mouth%20Rest%20Camp,%20South%20Africa&传感器=真
有没有办法获得自动完成预测的纬度/经度值?
或者,我不明白为什么谷歌自动完成正在返回我无法进行地理编码的预测.
这是我正在使用的逻辑和代码的基本示例:
var geocoder = new google.maps.Geocoder();
var service = new google.maps.places.AutocompleteService(null, {
types: ['geocode']
});
service.getQueryPredictions({ input: query }, function(predictions, status) {
// Show the predictions in the UI
showInAutoComplete(predictions);
};
// When the user selects an address from the autcomplete list
function onSelectAddress(address) {
geocoder.geocode({ address: address }, function(results, status) {
if (status !== google.maps.GeocoderStatus.OK) {
// This shouldn't never happen, but it does
window.alert('Location was not …Run Code Online (Sandbox Code Playgroud) 无论我正在尝试运行什么任务,都会发生这种情况.当--verbose我正在使用旗帜运行时:
初始化命令行选项: - verbose
阅读"Gruntfile.js"Gruntfile ......好的
注册Gruntfile任务.加载"Gruntfile.js"任务......好的
没有注册或未注册任务.
这是Gruntfile:
module.export = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
karma_coveralls: {
options: {
coverage_dir: 'coverage'
}
},
jshint: {
files: ['app/js/**/*.js', 'Gruntfile.js'],
options: grunt.file.readJSON('.jshintrc')
},
concat: {
options: {
seperator: ';'
},
dist: {
src: ['app/js/**/*.js'],
dest: 'dist/app/js/<%pkg.name%>.js'
}
},
exec: {
instrument: {
cmd: function () {
return 'istanbul instrument app/js -o app/instrumentjs';
}
}
}
});
grunt.loadNpmTasks('grunt-karma-coveralls');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('coverage', ['coveralls']);
grunt.registerTask('default', ['jshint']);
grunt.registerTask('instrument', ['exec: instrument']); …Run Code Online (Sandbox Code Playgroud) 我正在尝试找出使用UMD工厂测试Javascript模块定义的最佳方法,类似于:https://github.com/umdjs/umd/blob/master/returnExportsGlobal.js
我不想测试模块本身,我想测试模块是否在各种环境中正确"导出/创建":
我想使用grunt和jasmine来运行这些测试.我可以使用grunt-contrib-jasmine来测试第2点和第3点,但不是第1点.
我想我可以使用grunt-contrib-jasmine和grunt-jasmine-node的混合来测试正确的模块定义(具体实现我还需要弄清楚),但感觉非常混乱.
在很高的层面上,有没有人知道任何现有的方法来实现这一点而不使用多个grunt插件?
似乎我的项目grunt文件中的监视任务正在启动,然后立即退出.
请查看附带的屏幕截图.
请找到我的Gruntfile.js的代码;
module.exports = function (grunt) {
grunt.initConfig({
sass: {
options: {
cacheLocation: '.sass-cache'
},
prod: {
options: {
style: 'compressed'
},
files: [{
'assets/css/dist/main.min.css': 'assets/css/sass/main.scss'
}]
},
dev: {
options: {
style: 'nested'
},
files: [{
'assets/css/main.css': 'assets/css/sass/main.scss'
}]
}
},
imageoptim: {
files: [
'img/flat',
'img/flat/**'
],
options: {
imageAlpha: true,
jpegMini: true,
quitAfter: true
}
},
uglify: {
options: {
mangle: true,
compress: true
},
jsCompress: {
files: {
'js/dist/main.min.js': ['js/src/script1.js', 'js/src/script2.js']
}
}
},
concat: …Run Code Online (Sandbox Code Playgroud)