- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的情况是,我制作了一个被五个页面使用的ion-view
。这些页面是通过“标签式”菜单导航的,该菜单不使用 ion-tabs
或任何类似的东西(不是真正的问题所在)。我现在想为 Ionics scroll-delegate
使用动态值,但它似乎不起作用。我读过关于同一主题的其他问题(在 SO 和 Ionic 论坛上),但它们是 Ionic 1.0.0 左右时代的老话题,所提供的解决方案到今天还不起作用。
我的 ion-view
模板:
<ion-view>
<ion-content delegate-handle="{{category.id}}" on-scroll="scrollEvent(category.id)">
<h1>{{category.title}}</h1>
</ion-content>
</ion-view>
我的 Controller scrollEvent
函数:
$scope.scrollEvent = function(category) {
var scrollamount = $ionicScrollDelegate.$getByHandle(category).getScrollPosition().top;
if (scrollamount > 180) {
console.log('scroll amount > 180');
} else {
console.log('scroll amount < 180');
}
};
这会在控制台中发出以下警告:
Delegate for handle "12345" could not find a corresponding element with delegate-handle="12345"! getScrollPosition() was not called! Possible cause: If you are calling getScrollPosition() immediately, and your element with delegate-handle="12345" is a child of your controller, then your element may not be compiled yet. Put a $timeout around your call to getScrollPosition() and try again.
我已经尝试在 $ionicView.enter
$ionicView.afterEnter
和 $ionicView 上赋予
。我已经为函数设置了 10 秒等的超时时间,但这并没有帮助。delegate-handle
值。已加载
如果我手动设置 delegate-handle
并运行它,它就会工作。我需要动态设置它,因为不同的 View 应该有自己的 delegate-handle
以便我能够将它们彼此分开并相应地设置滚动位置等。类别的 ID 也可能会改变。
Ionic 在浏览页面时制作这些“ Pane ”(缓存它们),以便我可以查看并检查句柄是否正确。
<ion-view nav-view="active" style="opacity: 0.9; transform: translate3d(-33%, 0px, 0px);">
<ion-content delegate-handle="12345" on-scroll="scrollEvent(category.id)">
<h1>Category 12345 title</h1>
</ion-content>
</ion-view>
我不想去修改 Ionics 代码本身。
我已经制作了一个简单的演示,其中包含类似的功能供您试用,重复了问题:http://codepen.io/thepio/pen/xORdNG
有些人可能会说,显然我是从 http 请求中获取有关我的真实应用程序的数据(类别等)。
最佳答案
delegate-handle
的问题ionic 的指令是它实际上将字符串作为输入。因此,当您编写 {{myModel}} 时,它不会将其与模型的值进行插值,而是将“{{myModel}}”作为委托(delegate)句柄标识符。所以如果我们不想在等待 ionic 的团队解决这个问题的同时改变 ionic 的核心,这是我对这个问题的解决方案:
将 id 放在 ion-content
上以与分配委托(delegate)句柄相同的方式标记。 IE。 <ion-content id="{{category.id}}"></ion-content>
然后获取当前 View 处理程序的实际实例并使用它,这样它总是准确的(因为我们使用 id
属性作为使用以下代码的标识符:
//the idea is to get the specific instance of the handle element using ids, that's what we do in the function below in our controller.
$scope.getScrollPositionEpicly = function (category) {
var instances = $ionicScrollDelegate["_instances"];
//get all the instances that ionic scroll delegate is handling
var instance = null;
for(var index in instances){
if(instances[index].$element[0].id === category){ //match the instance that we're targeting using the id that we provided , i.e. the current view/handle/id on ion-content
instance = instances[index];
}
}
if(instance && instance.getScrollPosition){
return instance.getScrollPosition(); //return the correct position
console.log(JSON.stringify(instance.getScrollPosition()));
}
return {top:0,left:0}; //fallback case/default value so execution doesn't break
}
$scope.scrollEvent = function(category) {
// var scrollamount = $ionicScrollDelegate.$getByHandle(category).getScrollPosition().top;
var scrollPosition = $scope.getScrollPositionEpicly(category);
var scrollAmount = (scrollPosition.top || 0);
console.log("category : " + category);
console.log("scrollPosition : " + JSON.stringify(scrollPosition));
if (scrollAmount > 10) {
console.log('scroll amount > 10');
} else {
console.log('scroll amount < 10');
}
};
演示:这是working demo代码(检查控制台的输出)
希望这对您有所帮助。
关于javascript - Ionic scroll-delegate 的动态值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37961173/
我想在聚焦时使用 ion-input 更改 ion-item 内的 ion-label 颜色。 我可以使用 --highlight-color-focused: yellow; 更改 ion-item
我想用 ionic 3 ion-list (或任何在 Ionic 3 中有效的东西)来显示水平列表而不是典型的垂直列表。 寻找解决方案 没有大量的 css 或难以维护的代码。
我目前使用 ionic 和我的 cordova 插件同时开发一个应用程序。我想知道如何使用文件 plugins/fetch.json 从本地文件系统更新我的插件。有什么想法吗? 最佳答案 使用 ion
当我在 ionic 项目文件夹中运行 ionic link 命令时,我收到以下错误消息 “除非您在 Ionic 项目文件夹中,否则您无法运行此命令” 我的系统信息。 Cordova CLI:6.3.1
如何注释 ion-row这样它就可以填满剩余的空间? 对于以下示例,黄色行“内容”应展开,直到占用所有剩余(绿色)空间。 Example text
我正在尝试构建一个 ionic 应用程序,但是当我运行 npm run ionic:build -–prod 时,出现以下错误: npm run ionic:build -–prod npm ERR!
我想在 ion-footer-bar 中添加两个按钮,如图片,但我的代码无法正常工作。 Button 333333333 Button
请有人澄清一下我什么时候会使用 ion-nav-view反对 ion-view ?我正在学习 AngularJS/Ionic(我对 AngularJS 有基本的了解;并且想使用 Ionic 来增强它)
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 1年前关闭。 Improve t
item-avatar 在我的项目中不起作用,它根本不显示 item-avatar 元素。 Recent Conversations
我正在使用带有属性interface="popover"的ion-select。弹出窗口在 select 下方打开,这使得弹出窗口非常小。 我发现,如果 ion-select 中有 10 个或更多项目
我创建了一个带有电容器的新项目 ionic。我使用 ionic 选择,但我有一个新的 ionic 选择选项,带有大文本,而不是在输入中分布。 Plaga/Enfermedad Al
如何像 ionic 中的许多应用程序一样滑动切换段?我在 ionic 官方文档中找不到任何 api。我只能找到this有用的线程。 但它似乎并不完美。有更好的解决办法吗? ionic 信息: Cord
我正在开发一个登录表单,所以在我的 中我有一个 (用作登录表单的容器)我想垂直居中。我用 css flexbox 和其他 css 技巧尝试了不同的方法,但对我没有任何作用!该卡片保留在页面顶部。你
我想在 ionic 选择(组合框)更改时隐藏和显示文本框 例如我有: ionic 选择中的 1 和 2如果我选择 1 文本框将隐藏,如果我选择 2 文本框将出现 这是我当前的代码: .ts onCha
我尝试在 ionic 4 中使用 ion-button 实现一个按钮,但没有样式输出,问题出在哪里,求助。 最佳答案 请使用以下代码 这里是 ionic v4 按钮的文档。 https://beta
我有一个在 ionic serve 中运行良好的应用程序。我现在正在尝试创建一个构建——这通常有效,但今天我遇到了问题。 ionic package build ios --profile devel
我正在使用 Ionic 2,在我的应用程序中我正在创建一个表单,如果出现验证错误,信息图标将出现在相关输入字段的右侧。 HTML如下,
我正在与一个远程团队一起开发 Ionic 1 应用程序,最近我们的版本彼此不喜欢。我想知道我是否也一直在从事 Ionic 2 项目,无论出于何种原因,我的 CLI “认为”这些应用程序也是 Ionic
我需要禁用默认 ion-ripple-effect在“ ionic 按钮”中。 我无法禁用 pointer-events因为我需要它。 PS:我引用了以下帖子,但找不到适合 Ionic 4
我是一名优秀的程序员,十分优秀!